Setting the character encoding in form submit for Internet Explorer

HtmlInternet ExplorerFormsEncodingIso 8859-1

Html Problem Overview


I have a page that contains a form. This page is served with content type text/html;charset=utf-8. I need to submit this form to server using ISO-8859-1 character encoding. Is this possible with Internet Explorer?

Setting accept-charset attribute to form element, like this, works for Firefox, Opera etc. but not for IE.

<form accept-charset="ISO-8859-1">
  ...
</form>

Edit: This form is created by server A and will be submitted to server B. I have no control over server B.

If I set server A to serve content with charset ISO-8859-1 everything works, but I am looking a way to make this work without changes to server A's encoding. I have another question about setting the encoding in server A.

Html Solutions


Solution 1 - Html

There is a simple hack to this:

Insert a hidden input field in the form with an entity which only occur in the character set the server your posting (or doing a GET) to accepts.

Example: If the form is located on a server serving ISO-8859-1 and the form will post to a server expecting UTF-8 insert something like this in the form:

<input name="iehack" type="hidden" value="&#9760;" />

IE will then "detect" that the form contains a UTF-8 character and use UTF-8 when you POST or GET. Strange, but it does work.

Solution 2 - Html

With decent browsers:

<form accept-charset="ISO-8859-1" .... >

With IE (any):

document.charset = 'ISO-8859-1'; // do this before submitting your non-utf8 <form>!

Solution 3 - Html

It seems that this can't be done, not at least with current versions of IE (6 and 7).

IE supports form attribute accept-charset, but only if its value is 'utf-8'.

The solution is to modify server A to produce encoding 'ISO-8859-1' for page that contains the form.

Solution 4 - Html

I've got the same problem here. I have an UTF-8 Page an need to post to an ISO-8859-1 server.

Looks like IE can't handle ISO-8859-1. But it can handle ISO-8859-15.

<form accept-charset="ISO-8859-15">
  ...
</form>

So this worked for me, since ISO-8859-1 and ISO-8859-15 are almost the same.

Solution 5 - Html

If you have any access to the server at all, convert its processing to UTF-8. The art of submitting non-UTF-8 forms is a long and sorry story; this http://web.archive.org/web/20060427015200/ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html">document about forms and i18n may be of interest. I understand you do not seem to care about international support; you can always convert the UTF-8 data to html entities to make sure it stays Latin-1.

Solution 6 - Html

Just got the same problem and I have a relatively simple solution that does not require any change in the page character encoding(wich is a pain in the ass).

For example, your site is in utf-8 and you want to post a form to a site in iso-8859-1. Just change the action of the post to a page on your site that will convert the posted values from utf-8 to iso-8859-1.

this could be done easily in php with something like this:

<?php
$params = array();
foreach($_POST as $key=>$value) {
    $params[] = $key."=".rawurlencode(utf8_decode($value));
}
$params = implode("&",$params);

//then you redirect to the final page in iso-8859-1
?>

Solution 7 - Html

For Russian symbols 'windows-1251'

<form action="yourProcessPage.php" method="POST" accept-charset="utf-8">
<input name="string" value="string" />
...
</form>

When simply convert string to cp1251

$string = $_POST['string'];
$string = mb_convert_encoding($string, "CP1251", "UTF-8");

Solution 8 - Html

Looks like Microsoft knows [accept-charset](http://msdn.microsoft.com/en-us/library/ms533061%28VS.85%29.aspx "acceptCharset Property (FORM)"), but their doc doesn't tell for which version it starts to work...
You don't tell either in which versions of browser you tested it.

Solution 9 - Html

I seem to remember that Internet Explorer gets confused if the accept-charset encoding doesn't match the encoding specified in the content-type header. In your example, you claim the document is sent as UTF-8, but want form submits in ISO-8859-1. Try matching those and see if that solves your problem.

Solution 10 - Html

I am pretty sure it won't be possible with older versions of IE. Before the accept-charset attribute was devised, there was no way for form elements to specify which character encoding they accepted, and the best that browsers could do is assume the encoding of the page the form is in will do.

It is a bit sad that you need to know which encoding was used -- nowadays we would expect our web frameworks to take care of such details invisibly and expose the text data to the application as Unicode strings, already decoded...

Solution 11 - Html

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJuha Syrj&#228;l&#228;View Question on Stackoverflow
Solution 1 - HtmlTrygve LieView Answer on Stackoverflow
Solution 2 - HtmldgasparView Answer on Stackoverflow
Solution 3 - HtmlJuha SyrjäläView Answer on Stackoverflow
Solution 4 - HtmlChristianView Answer on Stackoverflow
Solution 5 - HtmlEdward Z. YangView Answer on Stackoverflow
Solution 6 - HtmlDavid Mongeau-PetitpasView Answer on Stackoverflow
Solution 7 - Htmldr.dimitruView Answer on Stackoverflow
Solution 8 - HtmlPhiLhoView Answer on Stackoverflow
Solution 9 - HtmlwarpView Answer on Stackoverflow
Solution 10 - HtmlpdcView Answer on Stackoverflow
Solution 11 - HtmlturbopackView Answer on Stackoverflow