Correct Way To Structure A Form

HTML 4.01 Strict W3 Compliance

Page 1 of 1

6 Replies - 2278 Views - Last Post: 21 May 2010 - 08:44 AM

#1 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Correct Way To Structure A Form

Posted 21 May 2010 - 03:19 AM

Hi all, I'm stuck on finding the correct way to do a form. Searching on this problem is a nightmare as using keywords like form and validation in the same query is obviously just going to bring up form validation from user input lol.

I have a page with a series of forms, each form has one or more inputs.
e.g.
<form>
[indent]<input type="submit" value="submit">[/indent]
</form>



The problem is that as input is an inline element it cannot go there, it must be contained in a block level element.
As you cannot put a div inside a form I decided to try fieldset, only to find out that in HTML 4.01 strict a fieldset requires a legend.
As far as I can see the only option left to me is a p tag.

Is using paragraph the only way around this?
Seems a bit counter intuitive as it is not a paragraph that I'm displaying.
If paragraph is the only way around this should I wrap each input in a paragraph? or just open a <p> at the start of the form and close it at the end of the form?

Any help and advice would be much appreciated.
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Correct Way To Structure A Form

#2 Quin  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 18
  • View blog
  • Posts: 359
  • Joined: 16-October 08

Re: Correct Way To Structure A Form

Posted 21 May 2010 - 03:26 AM

external
Was This Post Helpful? 0
  • +
  • -

#3 mr.coder  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 41
  • Joined: 31-January 10

Re: Correct Way To Structure A Form

Posted 21 May 2010 - 03:26 AM

To align out everything within a form, use a HTML Table.

To get a better idea on Tables, please visit:
http://www.w3schools...html_tables.asp

Hope it helps!
Was This Post Helpful? 0
  • +
  • -

#4 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Re: Correct Way To Structure A Form

Posted 21 May 2010 - 03:33 AM

View PostQuin, on 21 May 2010 - 02:26 AM, said:



The forms on the w3schools page are of the same format as the ones I have which do not validate in HTML 4.01 strict as input is an inline element and forms can only accept block level elements. Unless I am missing something.


View Postmr.coder, on 21 May 2010 - 02:26 AM, said:

To align out everything within a form, use a HTML Table.

To get a better idea on Tables, please visit:
http://www.w3schools...html_tables.asp

Hope it helps!


Hi thanks for the reply. I am trying to avoid using tables in forms as just like the paragraph option it just dosen't seem to make sense as I am not displaying a paragraph or tabular data.

Is there any option that makes semantic sense as well as validates with the w3 validator?

Thanks again!
Was This Post Helpful? 0
  • +
  • -

#5 Quin  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 18
  • View blog
  • Posts: 359
  • Joined: 16-October 08

Re: Correct Way To Structure A Form

Posted 21 May 2010 - 05:47 AM

Wait, so you want to validate a form? (Javascript/PHP can do this)
Was This Post Helpful? 0
  • +
  • -

#6 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 89
  • View blog
  • Posts: 10,079
  • Joined: 26-April 01

Re: Correct Way To Structure A Form

Posted 21 May 2010 - 06:13 AM

View PostQuin, on 21 May 2010 - 05:47 AM, said:

Wait, so you want to validate a form? (Javascript/PHP can do this)


no. this is exactly what he said he doesn't want.

validate as in run the code through a validator to make sure it is correct.
Was This Post Helpful? 1
  • +
  • -

#7 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Re: Correct Way To Structure A Form

Posted 21 May 2010 - 08:44 AM

Looks like I might have caused some confusion.

What I have is : (NOTE : <input ...> is used to clarify it could be anything textfield, password, button etc... it is irrelevant to the point.
<form>
<input ...>
<input ...>
</form>



Inputs (<input ...>) are inline elements which must cannot be nested inside a form as only block level elements such as <p></p> or <fieldset></fieldset> can be put inside a form.
In HTML 4.01 Strict if a fieldset tag is inside a form tag then a legend must be supplied.

Basically any of the following would be fine:
<form>
<p><input ...>
<input ...></p>
</form>


<form>
<p><input ...></p>
<p><input ...></p>
</form>


<form>
<fieldset>
<legend>Legend Text Goes Here</legend>
<input ...>
<input ...>
</fieldset>
</form>



I cannot see another way of accomplishing a form with it validating with the w3 validator.
To me using paragraphs makes no sense as the inputs are not paragraphs.
Tables make no sense as the inputs are not tabular data.
Divs cannot be used as a div cannot be placed within a form.
Fieldsets make little sense as they are meant to seperate out sections on a form, not contain the entire form. However it makes more sense than any other option I can find.

I have decided to use the fieldset approach and just put the form name as the legend and make it look the way I want using css.

I know I could use an empty legend tag and carry on as usual but that seems kind of pointless lol.

If anyone can see a better way of accomplishing this without fieldsets and legends I would be happy to hear it.

Thanks for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1