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.

JavaScript character encoding + Internet Explorer 9 coding

I have noticed stange things while performing tests. The stange things concern character encoding. For each test I have loaded an HTML page in my Internet Explorer 9 web browser. My HTML page is enc

Form with in Form submit request twice by Internet Explorer?

I have a Form which contains another form. When I’m submitting the nested form through javascript, It is submitting twice in Internet Explorer, but only one in any other browser. How to submit the nes

Cross Domain Ajax Form Submit in Internet Explorer

There’s this lead form on my website, which is integrated with zoho CRM. What i do is make an ajax form submit. It works perfectly in all the browsers except Internet Explorer. Here’s the code that I

Form submit problem using JavaScript in Internet Explorer 6

I have just done the code for submit the form using JavaScript. It works in all browsers except in Internet Explorer 6. I have pasted my HTML form and JavaScript code below. Can you please find what’s

angularjs Internet Explorer 10 form submit issue?

Post data was working perfectly in ie8. recently we migrated to ie10 then form post is suddenly stopped. Post-Template.html <form id=startDiscussionForm name=fileuload method=post enctype=mu

Input submit didn’t submit form with jquery in Internet Explorer

I create a HTML and jQuery code to submit a form with jQuery and it works in all browsers except Internet Explorer. HTML: <form name=file_upload id=file_upload action=<?php echo base_url();

stop form submitting in internet explorer

I am catching the form submission with jquery. This submit handler works in all browsers except internet explorer where it just does the submit. How can I fix it? $(‘#editForm’).live(‘submit’, functio

Form Submit button in MVC3/Razor doesn’t work in Internet Explorer

I have a form written in ASP.NET MVC3/Razor. The form post works perfectly well in Firefox and Chrome, but for some reason in Internet Explorer, the Submit button is unresponsive. To be clear, if an

form.submit() with JQuery returns character encoding error message

I’d like to submit a form with jQuery but it doesn’t work. I get this strange error message in Firebug (in German, sorry) and assume there is some strange character in the html? Die Zeichenkodierung

PHP form not working in Internet Explorer

I created this contact form, it works perfectly in firefox and chrome but in internet explorer it wont allow you to input text (clicking on the form fields does nothing) the submit button works but on

Answers

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…

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.

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.

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.

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.

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

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.

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

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.

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");

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