Retain values after validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dcp3450
Forum Newbie
Posts: 2
Joined: Tue Jul 14, 2009 2:07 am

Retain values after validation

Post by dcp3450 »

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:

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.";
    }
    
}
?>
 
form:

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>
 
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!
dcp3450
Forum Newbie
Posts: 2
Joined: Tue Jul 14, 2009 2:07 am

Re: Retain values after validation

Post by dcp3450 »

ok so, i found my first issue: textarea doesn't have a value option. I placed the $body between the open and closed tags and it works. However, I cant clear it now.
Post Reply