Jump to content

Form Validation


thescientist

Recommended Posts

http://validator.w3.org/check?uri=http%3A%...t%2Fcontact.phpSo I have a form on this page but it will not pass validation because it says that XHTML does not accept "value" as an attribute for the textarea element of my form, however I'm using value so that I can process the input of the text area through a php form. Any thoughts?here's the page, although you won't be able to see the PHP, which works fine btw, it's just keeping the page from validating. Sorry, I wasn't sure whether to put this here or in the PHP forum, but the PHP works (form sends the email) so I figured it was more of an (X)HTML issue as value seems to work for other form elements sending PHP, just not textarea.
Link to comment
Share on other sites

A textarea does not have a value attribute. The "value" is the text that appears between the <textarea> tags. That's why a textarea needs a closing tag, unlike other form input elements, which are self-closing. If a user enters text, or if you hardcode text between the tags, it will get posted to your script. You don't need to force a non-syntactic value attribute on the tag. If the text is not getting posted, something else is going wrong.(I should mention, for the sake of completeness, that if you want to access that text in javascript, you will find it in the value property of the textarea object. For the most part we can treat them the same, but in fact attributes and properties really are different things.)

Link to comment
Share on other sites

so I added </textarea> instead of making it self-closing, and now while the form works exactly like how I want, it still won't validate and still returns the error of value not being an acceptable attribute, EVEN though 'value' is what I am using on every other form item and none of those throw up an error, and whatever is in the special request form will still get sent on submission. So if value will not work, what can I use instead?

?>		<form id="inforequest" method="post" action="contact.php">		<h4>(**) Indicates a required field</h4>        <table class="width600 center" cellpadding="3" cellspacing="2">          <tr>             <td class="width150 left">First Name   **</td>            <td class="width150"><input type="text" name="FirstName" size="17" value="<?php if	(isset($_POST['FirstName'])) echo $_POST['FirstName']; ?>"/></td>            <td class="width150 left">Last Name   **</td>            <td class="width=150"><input type="text" name="LastName" size="17" value="<?php if	(isset($_POST['LastName'])) echo $_POST['LastName']; ?>"/></td>          </tr>          <tr>             <td class="left">Mailing Address</td>            <td><input type="text" name="MailingAddress" size="17" value="<?php if	(isset($_POST['MailingAddress'])) echo $_POST['MailingAddress']; ?>"/> </td>            <td class="left">Apt. #</td>            <td><input type="text" name="Apartment" size="17" value="<?php if	(isset($_POST['Apartment'])) echo $_POST['Apartment']; ?>"/></td>          </tr>          <tr>             <td class="left">City</td>            <td><input type="text" name="City" size="17" value="<?php if	(isset($_POST['City'])) echo $_POST['City']; ?>"/></td>            <td class="left">State/Province</td>            <td><input type="text" name="StateProvince" size="17" value="<?php if	(isset($_POST['StateProvince'])) echo $_POST['StateProvince']; ?>"/></td>          </tr>          <tr>             <td class="left">Zip/Postal Code</td>            <td><input type="text" name="ZipPostalCode"  size="17" value="<?php if	(isset($_POST['ZipPostalCode'])) echo $_POST['ZipPostalCode']; ?>"/> </td>            <td class="left">Country</td>            <td><input type="text" name="Country" size="17" value="<?php if	(isset($_POST['Country'])) echo $_POST['Country']; ?>"/></td>          </tr>          <tr>             <td class="left">Telephone #   **</td>            <td><input type="text" name="Telephone"  size="17" value="<?php if	(isset($_POST['Telephone'])) echo $_POST['Telephone']; ?>"/></td>            <td class="left">E-mail Address   **</td>            <td><input type="text" name="EmailAddress"  size="17" value="<?php if	(isset($_POST['EmailAddress'])) echo $_POST['EmailAddress']; ?>"/></td>          </tr>        </table>        		<div class="center">		<h3>Information or Special Requests   **</h3>        <textarea name="SpecialRequest" cols="60" rows="8" value="<?php if	(isset($_POST['SpecialRequest'])) echo $_POST['SpecialRequest']; ?>"></textarea>		<br/>		<br/>        <input type="submit" name="submit" value="Submit"/><input name="Reset" type="reset" id="Reset" value="Reset"/>		<input type="hidden" name="Submit" value="email_contact"/>		</div>      	</form> 

Link to comment
Share on other sites

so I added </textarea> instead of making it self-closing, and now while the form works exactly like how I want, it still won't validate and still returns the error of value not being an acceptable attribute, EVEN though 'value' is what I am using on every other form item and none of those throw up an error, and whatever is in the special request form will still get sent on submission. So if value will not work, what can I use instead?
?>		<form id="inforequest" method="post" action="contact.php">		<h4>(**) Indicates a required field</h4>        <table class="width600 center" cellpadding="3" cellspacing="2">          <tr>             <td class="width150 left">First Name   **</td>            <td class="width150"><input type="text" name="FirstName" size="17" value="<?php if	(isset($_POST['FirstName'])) echo $_POST['FirstName']; ?>"/></td>            <td class="width150 left">Last Name   **</td>            <td class="width=150"><input type="text" name="LastName" size="17" value="<?php if	(isset($_POST['LastName'])) echo $_POST['LastName']; ?>"/></td>          </tr>          <tr>             <td class="left">Mailing Address</td>            <td><input type="text" name="MailingAddress" size="17" value="<?php if	(isset($_POST['MailingAddress'])) echo $_POST['MailingAddress']; ?>"/> </td>            <td class="left">Apt. #</td>            <td><input type="text" name="Apartment" size="17" value="<?php if	(isset($_POST['Apartment'])) echo $_POST['Apartment']; ?>"/></td>          </tr>          <tr>             <td class="left">City</td>            <td><input type="text" name="City" size="17" value="<?php if	(isset($_POST['City'])) echo $_POST['City']; ?>"/></td>            <td class="left">State/Province</td>            <td><input type="text" name="StateProvince" size="17" value="<?php if	(isset($_POST['StateProvince'])) echo $_POST['StateProvince']; ?>"/></td>          </tr>          <tr>             <td class="left">Zip/Postal Code</td>            <td><input type="text" name="ZipPostalCode"  size="17" value="<?php if	(isset($_POST['ZipPostalCode'])) echo $_POST['ZipPostalCode']; ?>"/> </td>            <td class="left">Country</td>            <td><input type="text" name="Country" size="17" value="<?php if	(isset($_POST['Country'])) echo $_POST['Country']; ?>"/></td>          </tr>          <tr>             <td class="left">Telephone #   **</td>            <td><input type="text" name="Telephone"  size="17" value="<?php if	(isset($_POST['Telephone'])) echo $_POST['Telephone']; ?>"/></td>            <td class="left">E-mail Address   **</td>            <td><input type="text" name="EmailAddress"  size="17" value="<?php if	(isset($_POST['EmailAddress'])) echo $_POST['EmailAddress']; ?>"/></td>          </tr>        </table>        		<div class="center">		<h3>Information or Special Requests   **</h3>        <textarea name="SpecialRequest" cols="60" rows="8" value="<?php if	(isset($_POST['SpecialRequest'])) echo $_POST['SpecialRequest']; ?>"></textarea>		<br/>		<br/>        <input type="submit" name="submit" value="Submit"/><input name="Reset" type="reset" id="Reset" value="Reset"/>		<input type="hidden" name="Submit" value="email_contact"/>		</div>      	</form> 

Put the "value" of the textarea in between the tags:
<textarea name="SpecialRequest" cols="60" rows="8"><?php if (isset($_POST['SpecialRequest'])) echo $_POST['SpecialRequest']; ?></textarea>

Link to comment
Share on other sites

Put the "value" of the textarea in between the tags:
<textarea name="SpecialRequest" cols="60" rows="8"><?php if (isset($_POST['SpecialRequest'])) echo $_POST['SpecialRequest']; ?></textarea>

this guy.... :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...