0

I get thrown out a bunch of errors on the xhtml 1.1 validator (W3C) whenever I use a element.

As soon as I change the element to a <div> all the errors disappear.

In browsers the forms work in both states (as a <div> or as a <form> element, minus the fact that when I use <div>, the submit button will not work.

Anyone have any ideas as to why the it's coming up as invalid?

<form class="form"> 
        Name:<br/>
        <input type="text" name="firstname"/><br/>
        Email Address:<br/>
        <input type="text" name="email"/><br/>
        Comments:<br/>
        <textarea name="Comments" rows="10" cols="50">Please enter your comments here.</textarea><br/><br/>
        <input type="submit" value="Done"/><br/>
    </form>

LINK: Screenshot of a few of the validator errors

Sirko
  • 72,589
  • 19
  • 149
  • 183
Osprey
  • 3
  • 4

1 Answers1

1

Not sure why the question, because the validator is telling you exactly what's wrong.

You need an action attribute on your form.

Don't use <br> to format your markup.

Surround your input labels in actual <label> elements, and have them associated with their appropriate inputs via the for attribute matching the input's id. In XHTML you can't have text in the document that isn't appropriately wrapped in an element.

<form action="#insert_your_action_here">
  <label for="first_name" class="block-label">
    Name:
  </label>
  <input type="text" id="first_name" name="firstname">
</form>

Use CSS to format your labels and inputs:

.block-label { 
  display: block;
}
scottohara
  • 727
  • 4
  • 11
  • Thanks for that, I literally have only been doing HTML properly for under a week, it just through me is all xD – Osprey Apr 29 '17 at 12:53
  • np and good luck. A good resource you may want to check out, for learning HTML, would be MDN (google mdn html). – scottohara Apr 29 '17 at 13:06