views:

9550

answers:

9

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.

A: 

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...

pdc
A: 

Looks like Microsoft knows accept-charset, 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.

PhiLho
A: 

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.

warpr
I have a similar problem. The application serves the response as utf-8 and in the form it is specified accept-charset="utf-8" but with IE8 it retrieves the values with wrong format. What is the best configuration to work with forms with Internet Explorer?Thanks.
David García González
+1  A: 

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 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.

Edward Z. Yang
I do care a lot about international support, and I'd like to keep my app in UTF-8 world, but this single page needs to be submitted in iso-8859-1 to external server.
Juha Syrjälä
+1  A: 

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.

Juha Syrjälä
IE only uses `accept-charset` as a ‘backup’, when it has failed to encode a fields in the page's own charset. Specify `accept-charset` and you won't be able to tell which encoding was used. It is, therefore, utterly useless; it should never be used. The only solution is, indeed, to change the charset of the page (or iframe) containing the form.
bobince
A: 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+3  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 are 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 UFT-8 when you POST or GET. Strange, but it does work.

This does not seem to work for the inverse situation. Posting a form which stays on a utf-8 page to an iso-8859-1 page on an other server.
MaxiWheat
Right, it won't work the other way. Wenn you specify something like "ÿ" which is the "highest" Char in the ISO-8859-1 charset, this obviously is an UTF-8 code, too. So, IE therefore thinks it's UTF-8. So it only works when the target charset has a greater amount of characters.
acme
A: 

I've experimented the hack suggested by Trygve Lie inserting the following input field:

<input type="hidden" name="cod_hack" value="&#153;">

and it works! Great! This allows me not to move all the site from latin-1 to utf-8. Thanks.

+1  A: 

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
?>
Mongo