SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validation Error! Carnt place <label> or <input> inside a <form> tag!

    Hello,

    I have been recently getting validation errors when creating forms!

    I keep getting told that I cannot place <input> or <label> tags within a <form> element! I do not understand this, as I throught that is where they are supposed to go! The site/page in question can be seen here:

    http://new.forepoint.co.uk/news/

    The errors are being produced on the search field in the side bar!

    If anyone could shine some light on this, that would be great!

    Regards

    Shaun

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2009
    Location
    Baton Rouge, LA
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found one site so far that does not list form as a parent to input. I would suggest wrapping your form fields in a fieldset and see if that validates. I am still looking for the w3 specs that would verify this.

    http://www.utoronto.ca/webdocs/HTMLd...ict/input.html

    Looks like forms need to start with a block level element in strict doc types to validate.
    "The browser is your first client" - Quote: Myself
    Please visit me at: vanillacloud.com

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats the one! I didnt no you had to use fieldsets! Well you learn something everyday! Thanks for you help!

    Shaun

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't want to use a fieldset, you can choose a different structural element, such as div, p, or ul/li to contain a form control.

  5. #5
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    Certain block elements (like form and body and blockquote) are, for whatever reason, not allowed to have inline elements (such as labels, inputs, selects) as direct children. They can be grandchildren. This is why using a fieldset, or a div, or whatever, removes the error message.

    If you're using HTML4 you need a legend with your fieldset. You won't get an error from the validator though if you are also wrapping your label-input pairs in divs for some reason. XHTML1 doesn't require the legend with the fieldset. Still it's considered Good Practice to use them.

    Why I don't use fieldsets on one- or two-question forms, like search or logins. They're so self-explanitory I use divs and no legends.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •