PHP Complete Form Example


This chapter shows how to save the input fields values ​​when the user clicks the submit button.


PHP - Keep The Values in The Form

To display the input field values ​​after a user clicks the submit button, add a small PHP text within the value of the input field value: name, email, and website. In the comment text field, we place text between the tags. The text is subject to $ name value, $ email, $ website, and $ comment comments.

Then, we also need to indicate which radio button has been tested. In this case, we must use the tested attribute (not the total number of 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


PHP - Complete Form Example

Here is the complete code for the PHP Form Verification Form:


Example