Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 validation form tag

"The for attribute of the label element must refer to a form control."

Honestly, I don't understand what's wrong with the markup. I've looked through so much of the W3's site and just can't get it.

Help?

HTML:

<form action="process.php" method="post">
    <div>
        <label for="name">Name</label><br />
        <input type="text" value="" name="name" />
    </div>
    <div>
        <label for="email">E-mail</label><br />
        <input type="text" value="" name="email" />
    </div>
    <div>
        <label for="message">Message</label><br />
        <textarea name="message" cols="30" rows="4"></textarea>
    </div>
    <div>
        <input type="checkbox" value="yes" name="newsletter" />
        <label for="newsletter">Subscribe to newsletter</label>
    </div>
    <div>
        <input type="submit" value="Submit" name="subscribe" />
    </div>
</form>
like image 426
technopeasant Avatar asked Feb 28 '11 02:02

technopeasant


2 Answers

You're missing the id attribute.

So to fix it, for example:

<input type="text" value="" name="email" id="email" />

That's it. Linky.

like image 115
thirtydot Avatar answered Oct 01 '22 04:10

thirtydot


Thirtydot is correct; there is amissing id in your form. I have added all. Check this:

<form action="process.php" method="post">
    <div>
        <label for="name">Name</label><br />
        <input type="text" id="name" value="" name="name" />
    </div>
    <div>
        <label for="email">E-mail</label><br />
        <input type="text" id="email" value="" name="email" />
    </div>
    <div>
        <label for="message">Message</label><br />
        <textarea name="message" id="message" cols="30" rows="4"></textarea>
    </div>
    <div>
        <input type="checkbox" id="newsletter" value="yes" name="newsletter" />
        <label for="newsletter">Subscribe to newsletter</label>
    </div>
    <div>
        <input type="submit" value="Submit" name="subscribe" />
    </div>
</form>
like image 44
Varun Sridharan Avatar answered Oct 01 '22 02:10

Varun Sridharan