Forum Moderators: open

Message Too Old, No Replies

Set accept-charset for all <form> on domain

         

csdude55

6:11 pm on Nov 3, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My site sets the charset to UTF-8 in the header, and I only want to accept UTF-8 when a user submits a form.

I know that I can do this in each <form> tag:

<form accept-charset="UTF-8">

I'm pretty sure that the answer is "no", but is there ANY way to make every <form> tag on the site include this without manually changing every one of them?

All of my display pages are written in PHP, and most of the processing is done via Perl. My initial thoughts were that it might be able to be done in Apache config, or even CSS, but I'm not finding anything.

lucy24

9:36 pm on Nov 3, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the whole page is written in php, why would you need to manually change anything? (In fact, why would you need to do so even in hand-rolled HTML? It’s a global replace with a suitably talented text editor.)

Looking it up, I find a Q&A from 26 (twenty-six) years ago, referencing a problem in Netscape. Seriously, Google? That's one of the ten most useful and relevant articles on the subject?

I did find one place that says w/r/t “accept-charset” in forms
If not specified, the default is the same as the page character encoding
but I am not absolutely certain I believe them.

csdude55

4:02 am on Nov 4, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the whole page is written in php, why would you need to manually change anything?

I'm not really dealing with a single page, I'm dealing with dozens of pages with forms.

I guess that I could do something scary like this via SSH:

grep -RiIl '<form ' | xargs sed -i 's/<form /<form accept-charset="UTF-8" /g'

but I'm not going to do that for fear of accidentally catching something it shouldn't. So I'd end up manually editing every file just to feel better about it.

I've spent some time trimming the fat throughout the site, though, and this adds 24 bytes to every page. I know, I know, that's microscopic, but still, it adds to the load time. PLUS, there's no telling whether browsers in the next 2 years will stop liking this attribute, or that UTF-8 will become an issue for some reason. So if there's a way that I could just add something once to Apache config or something so that it's only 24 bytes once instead of one very page, and could easily be removed in the future, then I would rather do that.

lucy24

4:40 pm on Nov 4, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I did a little more reading after I posted. I am now more inclined to believe them when they say that, barring a different "accept-charset" declaration, forms default to the page's overall charset. Officially the default value is "accept-charset='UNKNOWN'" where UNKNOWN is interpreted as, I guess, "inherit".