Validate forms XHTML 1.0 Strict
Thanks for visiting! If you're new here, you may want to subscribe to our RSS feed. This blog posts regular Wordpress news, updates of themes, plugins, ideas, hacks, quick fixes and everything about blogging, especially about Wordpress. Go ahead, subscribe to our feed! You can also receive updates from this blog via email.
I ran into some trouble with the forms validation because I was using a javascript:document.formname.submit() which would require a name for the form. As it turns out, form name is deprecated in XHTML 1.0 Strict and XHTML 1.1.
In other words <form name="blah" ... > is not valid in XHTML 1.0 Strict and XHTML 1.1.
To get around this issue, I used <form id="blah" ... > and in my link I used javascript:document.forms['blah'].submit(); which validates correctly.
Also, to get around the carriage return problem in input tags of forms (for input tags to validate correctly in XHTML 1.0 Strict and XHTML 1.1, they have to surrounded by <p> or h1 etc. ) I surrounded my inputs by (gasp) fieldsets and then hid it by styling the fieldset so I could get them all in one line. Im sure a lot of people know about these already, but this is for my future reference.


(20 votes, average: 4.8 out of 5)










Comments RSS
I doubt if that works with real XHTML. I guess this is more the solution for HTML 4.01 Strict.
If you enclose your form in a div, you won’t get all those “name” errors, and you then need not enclose each input tag in a separate container (or hidden fieldset).
For details see Forms in XHTML 1.1.
Thanks for your “name” tip. I was able to update the following form to XHTML 1.0 strict.
Text Area HighLight
Abid Omar: FORM still cant have the “name” tag.
Thanks for the tip man!
This was just what I needed for my javascript to work, and also to be able to validate my site as xhtml 1.1 strict. Thank you
The id instead of name in a form can be a tricky part, but this solves it nicely.
thanks a lot ) very useful tip!
3rd place in google by “xhtml strict form name” =)
respect from russia ^^
Actually, in XHTML Strict, if you simply nest your form inside of a div, your XHTML will still not validate. All form elements (labels, input tags, etc) must be contained in a block-level element like a fieldset or a paragraph tag in order to validate.
I found this technique of using an “id” attribute in the form tag to work beautifully in XHTML Strict. I modified this slightly since my form calls a JavaScript function. I gave my form an id of “FormA” and in my JavaScript, I used this statement to talk to the form: var form = document.forms['FormA'];
Thanks for the tip!
Thanks for the tips dude. Worked a treat.
Here’s how I used it.
There is a easier way.
document.forms[ 0 ].submit()
I still prefered using then using an ID, if there is no name, some extension in dreamweaver will not work, it will say please name your form first, stupid that it does validate correctly using xhtml strict, but hey the name inside a form still works anyway, forget the rule.
Thanks!! works perfect! Xhtml 1.0 STRICT