Retain values after validation
Posted: Tue Jul 14, 2009 2:15 am
I know this is simple but I've been searching for a easy way to retain the text in a textarea field if the user fails validation:
php:
form:
I have tried setting value to $body, <?php echo $body; ?>, <?php $_POST['body'] ?>, etc. but nothing works. I can put
<?php
echo $body;
?>
in the form, press submit and it shows the text that was entered but I can't get the value to accept it. Any help or push in the right direction would be great!
php:
Code: Select all
//email validation is up here
if ($name == "")
$message .= "Name is required. ";
if ($email == "")
$message .= "Email is required. ";
else
{
if (confirm_email($email))
header("Location: url");
else
$message .= "Email is invalid.";
}
}
?>
Code: Select all
<form action="contactus.php" method="post" name="contact">
<?php
if ($message !="")
echo $message;
?>
<br />
<label for="name">Name:</label><input name="name" type="text" size="30" id="textfield" /><br />
<label for="email">Email:</label><input name="email" type="text" size="30" id="textfield" /><br />
<label for="subject">Subject:</label><select name="subject" id="subject">
<option value="test subject1">Test Subject 1</option>
<option value="test subject2">Test Subject 2</option>
<option value="test subject3">Test Subject 3</option>
</select><br />
<textarea name="body" id="body" cols="60" rows="15" value="WHAT GOES HERE?" ></textarea><br />
<input name="submit" type="submit" value="Send" /><input name="reset" type="reset" value="Clear" />
<input type="hidden" name="process" value="1" />
</form>
<?php
echo $body;
?>
in the form, press submit and it shows the text that was entered but I can't get the value to accept it. Any help or push in the right direction would be great!