Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP Form Complete

PHP – Keep The Values in The Form

To display the values in the input fields after the user submits the form, we add a small PHP script inside the value attribute of the name, email, and website fields. For the comment textarea field, we place the script between the <textarea> and </textarea> tags. This script outputs the values of the $name, $email, $website, and $comment variables.

We also need to indicate which radio button was selected by manipulating the checked attribute (not the value attribute for radio buttons):

Name: <input type="text" name="name" value="<?php echo $name;?>">
E-mail: <input type="text" name="email" value="<?php echo $email;?>">
Website: <input type="text" name="website" value="<?php echo $website;?>">
Comment: <textarea name="comment" rows="5" cols="40"><?php echo $comment;?></textarea>
Gender:
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="female") echo "checked";?>
value="female">Female
<input type="radio" name="gender"<?php if (isset($gender) && $gender=="male") echo "checked";?>
value="male">Male
<input type="radio" name="gender"<?php if (isset($gender) && $gender=="other") echo "checked";?>
value="other">Other