Subscribe to the RWT RSS Feed

RWT Webmaster Tools Blog

Resources and Tools You Can Use

 

Validating forms in xhtml strict

Here is a sample to follow in order to make any form validate under xhtml strict rules:

<form action=”some bit of code here” method=”post” >

<fieldset>

<label>Enter your email address:</label>
<input type=”text” name=”email” />
<input type=”hidden” value=”some value” name=”url”/>
<input type=”hidden” value=”some value” name=”title”/>
<input type=”submit” value=”Subscribe” />

<p>Powered by <a href=”a url”>Something</a></p>

</fieldset>

</form>

The key: put the fieldset tag around ALL the input statements.

[tags]xhtml, form[/tags]

comments / trackbacks

10 Responses to “Validating forms in xhtml strict”

  1. Darren Hudson Says:

    your solution works for me to valid hidden input types, but a rounded rectangle appears around the form. do i need to add something to make this border invisible?

  2. Darren,

    Very good question.

    In you CSS file put the following:

    fieldset {
    border: 0;
    }

    This will remove the border around any fieldset tags in your code. Fieldset automatically creates a border around the objects it encloses. To learn more about fieldset check out this page.


  3. sander-martijn Says:

    As someone who’s done development for more than 13 yrs in all different languages, I have to say that’s the dumbest aspect of the new standards I’ve heard yet. Let’s just throw in another useless tag that does nothing for markup but defaults to something no one wants so everyone has to add in 3 lines of extra css…. wow. well thanks for straightening it out for me as the idea of input not validating inside form was almost as irritating to me as the solution.

  4. that little css hack is invalid:
    Value Error : border only 0 can be a length. You must put a unit after your number : 1

  5. Great this has helped me!
    and the css does validate.

  6. That last comment isn’t very clear, but if you’re using “border:0;” you’re setting the border off, which doesn’t require a unit of measurement. If you’re trying to set the border to “border:1;” then you have to include a unit as in “border:1px;”

  7. [...] 31.05.2009 | 22:13 | #3 http://www.recommendedwebtools.com/i…-xhtml-strict/ [...]

  8. Thank you, thank you, thank you. You’re solution to add around the form elements worked like charm.

  9. Thank you! I was looking for it …

  10. Thanks a million !! I had a really complicated form with with drop-downs & calls to MySQL dbase – all works fine. Put 2 simple “Click to turn off / on” buttons in a seperate page and all hell broke loose – Yikes !!! I had to set the padding to zero, as well as border – just in case someone is still having problems.

    Phill.

Leave a Reply