Is form charset required?

2019-08-10 05:42发布

问题:

My website is set to UTF-8, do i have to set my forms also to utf-8 using the accept-charset for forms?

My guestbook for example allows multi-language so my guestbook database table is utf8_unicode_ci and all my webpages use the same template so the encoding for all pages is utf-8, because I set the charset for my webpages as utf-8 do i have also set the form charset to utf-8 or no because I already set it for the webpage itself?

Reason why is I am converting my website to utf-8 and don't really want to go through all my site forms adding the form charset utf-8 attribute.

回答1:

Almost every decent browser ignores the accept-charset attribute in favour of the encoding of the page with the form as it is defined in charset param of the Content-Type response header. The attribute works as far only in MSIE and even then, it is using it wrong. In MSIE running on Windows, any other value than UTF-8 would be interpreted as CP-1252.

Don't use this attribute. It's useless.



回答2:

Typically if the page is served explicitly with UTF-8, the form inputs will also be encoded in that character set.



回答3:

It defaults to the character encoding/charset that the page was served with. You just need to ensure your response header has content-type with charset=utf-8