Welcome to WebmasterWorld Guest from 54.159.246.164

Forum Moderators: incrediBILL

Message Too Old, No Replies

validating to strict with textarea

sgml parser

   
7:31 am on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hello everyone,

I had a problem last night that has suprised me, either that or I have not noticed it before:-

<div class="formcontainer">
<form method="post">
<textarea name="mytextarea">
Hi there!
</textarea><br/>
<input type="submit" name="submit" value="submit">
</form>
</div>

I thought as this would be perfectly fine going though the validator, but it turns out as it needs nesting :-

<div class="formcontainer">
<form method="post">
<p><textarea name="mytextarea">
Hi there!
</textarea>
</p>
<br/>
<p><input type="submit" name="submit" value="submit"></p>
</form>
</div>

Or is this just the difference between transitional & strict?

This may seem trivial, but I thought that having the entire form encased in 1 div would be ok, but adding the <p> tags around each element made it validate properly.

Maybee I have missed a day at html school somwhere along the line ;-p but it just caught me out for half hour last night.

Cheers,
MRb
10:48 am on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member kaled is a WebmasterWorld Top Contributor of All Time 10+ Year Member



There are some bonkers rules in strict, so I don't bother with it most of the time (except when I'm writing example code).

If you use a <div> within the <form> to contain all elements, it should be ok. This will avoid applying unwanted CSS rules for <p> to the <textarea>. I think I did this a while back for some bit of code somewhere but I'm not certain.

Kaled.
12:30 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there Kaled,

Yes, with respect to using a single div to "hold" a form,I thought as I would be Ok. There is no discernable difference having the <p> tags there or not, at least I cant see it. I suppose that this gives you the option of dressing up the elements aesthetics at a later date.

Cheers,
MRb
2:59 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



As defined in the HTML 4.01 Spec. [w3.org], the form element can only contain block elements (like div and p) or script element.

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

Therefore, it's usually best to do something like this:

<form ...>
<div>
...
</div>
</form>

You can still have a "formcontainer" div around the form as well if you want, but it might make more sense to just make the inner div element the "formcontainer" (assuming you're styling that element in some way).
4:05 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member kaled is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I thought that's what I said, but not as clearly I guess!
4:22 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Yes, you did. I just wanted to clarify that this was not something new or specific to the strict DTD, and provide the details of "why". :)
8:20 pm on Apr 15, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi guys,

Thanks for the explanations, Kaled, you had explained perfectly, more than likely human error on my part! I since re-read the thread, and when I looked over the my code, I realised that I hadn't placed a div on the inside of the form, hence why I was surprised when placed a generic p tag in there and the strict validator came back as Ok. I had only placed one on the outside, the container in essence.

I have since placed an internal Div, instead of the p tags and everything is Ok.

I have only recently started to use strict, as I thought I was already coding to that standard within the context of transitional. I am too which is good news, just something as trivial as that caught me out ;-p

Again, thanks for the advice & links,

Cheers,
MRb