Forum Moderators: open

Message Too Old, No Replies

HTML Form Validation Problem

Form validation problems...

         

madcat

4:47 am on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't seem to get a form to validate with the W3C. Everything seems to check out fine to me unless I'm missing something simple.

Possible cause is an inline element containing a block level element...

<div id="right">
<form action="index.html" method="post">
<input class="go" type="image" src="images/searchcat2.gif" /><br />
<input type="text" name="submit" size="22" />
</form>
</div>
---------------------------------------------
Everything validates without the <form> there.

Thanks as always-

brotherhood of LAN

8:39 am on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hello madcat

I put your above code in the HTML validator inside a basic page and did not get any errors.

I know that sometimes the W3C validator will say that a particular tag is creating a problem when in fact its another tag further up the page.

You might want to check your closing tags further up the page as they might be causing the problem.

/added
I didn't read that "everything else validates"...seems odd!

Nick_W

10:21 am on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I presume you're validating against an xhtml doctype, right madcat?

This'll fix it:


<div id="right">
<form action="index.html" method="post">
<p>
<input class="go" type="image" src="images/searchcat2.gif" /><br />
<input type="text" name="submit" size="22" />
</p>
</form>
</div>

Nick

tedster

1:21 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nick, that seems a bit mysterious to me. Why are the paragraph tags needed?

bird

2:50 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The paragraph tags aren't needed, the original code validates without them (for XHTML 1.0 transitional in my test, but probably in any other HTML version as well).

I suspect that you have some other element on the same page, that encloses this code fragment and has display:inline characteristics.

andreasfriedrich

2:53 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the strict variant of XHTML 1.x and HTML 4.x form elements may only contain script elements or block-level elements except for form elements.

Input and br elements are defined as inline elements. Therefor they must not be used directly within form elements. The additional p element (any other block-level element would have worked just als well) is a block-level element and as such allowed within the form element.

Block-level elements may contain inline elements such as input and br.

madcat

3:08 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nick, that worked fine:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-------------------------------------------------

Input and br elements are defined as inline elements. Therefore they must not be used directly within form elements.

I thought that the <form> element was mostly block level, therefore, <input> and <br /> would be in their correct places.

Seems I have some catching up to do;)
Thanks for your help everyone.

andreasfriedrich

3:25 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought that the <form> element was mostly block level

It is indeed, only that in the strict (X)HTML variants there are additional restraints as pointed out above. Have a look at [htmlhelp.com...] and [w3.org...] for more infos.

bird

3:41 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Input and br elements are defined as inline elements. Therefore they must not be used directly within form elements.

The standard doesn't provide any comments as to why this is supposed to make any sense, but you're right, it is indeed defined that way for the strict versions. The guys from the w3c normally have very good reasons for the the restrictions they define, but this one really has me scratching my head. One more reason to stick with the transitional definitions for the moment... ;)

[edited by: bird at 3:42 pm (utc) on Aug. 24, 2002]

tedster

3:41 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks andreas for the enlightenment. I haven't worked with strict doctypes so far, so this was completely new to me. I'm sure I'll need to use the knowledge very soon.

madcat

3:45 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, thanks for the links andreasfriedrich.

Nick_W

4:14 pm on Aug 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, it's a weird one. Took me bloody ages to work out why my forms wer'nt validating when I switched to xhtml 1.1 .....

You live and learn ;)

Nick