Setting the character encoding in form submit for Internet Explorer
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.
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="☠" />
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.
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>!
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.