By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,445 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,445 IT Pros & Developers. It's quick & easy.

input tags in forms and xHTML...

P: 4
Hi All,

I have a question regarding the use of the input tag in forms when using xHTML 1.1 strict.

Basically I'm getting errors suggesting the input tag is not allowed inside the form e.g: document type does not allow element "input" here; missing one of "ins", "del", "h1", "h2", "h3", "h4", "h5", "h6", "p", "div", "address", "fieldset" start-tag.

I've heard mention of the input tag not existing in xHTML strict, but I'm a) not sure if that is true and b) am not aware of an alternative.

The code in question is shown below:
[HTML]<div class="siteproject">
<p class="h8">Iris</p>
<p><a href="img/iris.html" class="projectlink">click to enlarge</a></p>
<p><a href="img/iris.html" class="projectimg"><img src="img/jpg/irissmall.jpg" alt="iris image" class="projimg"/></a></p>
<p>Iris - &pound;28.95</p>
<form action="" method="post">
<input type="hidden" name="storeid" value="12345"/>
<input type="hidden" name="price" value="28.95"/>
<input type="hidden" name="quantity" value="1"/>
<input type="hidden" name="itemname" value="Iris Kit"/>
<input type="submit" value="Add to Basket"/>
<!-- END CART CODE -->

I cannot see any particular reason why this would not be correct code, except for perhaps my css div declaration implying an inline element, so maybe the validator see's it as a <p> or equivilent and doesn't like the form or input tags being inside it.

Can anyone shed any light on this? It's bugging me now!
Mar 11 '07 #1
Share this Question
Share on Google+
6 Replies

Expert 5K+
P: 7,435
You have the form inside the <p> but it is the <input> elements that must be inside a <p> or <div>.
Mar 11 '07 #2

P: 4
I don't think the form is inside a <p> but I will try enclosing the inputs inside this and see if it validates, thanks for the advice
Mar 11 '07 #3

Expert 5K+
P: 7,435
Yes, you are right. I saw the <p> in front of Iris but not the closing </p> at the end of the line. But the inputs do need to be inside a <p> or <div> or other elements.

btw, you should not be using xhtml 1.1. v1.1 is pure xml and intended to be served as such. You are probably serving it as text/html.
Mar 11 '07 #4

P: 4
Thanks for the tip, the page will validate fine with the inputs surrounded in <p>'s

I think originally i misinterpreted the advice from someone to include the inputs in a <div>. I assumed one div around the lot what suffice, but obviously not!

Thanks again,

Mar 11 '07 #5

P: 4
Interesting comment about the usage of xHTML 1.1, I simply assumed it was wise to code the html to the latest spec. I am using the following doc type:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">

Are you saying that really that should only be used for straight XML? if so, can you suggest a better alternative?

I am a little reluctant to change as I do like the way it parses certain elements.
Mar 11 '07 #6

Expert 5K+
P: 7,435
From the W3C:
Why is it disallowed to send XHTML 1.1 documents as text/html?

XHTML 1.1 is pure XML, and only intended to be XML. It cannot reliably be sent to legacy browsers. Therefore XHTML 1.1 documents must be sent with an XML-related media type, such as application/xhtml+xml.
In addition, if you serve the page as text/html then the browser will interpret it as html and throw everything else out.
Mar 11 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.