PHP full form instance


This section describes how to get users to ensure that all fields are entered correctly before submitting data by clicking the submit button.


PHP - Make sure you enter a value in the form

After the user clicks the submit button, to ensure that the field values are entered correctly, we insert PHP scripts in the input elements of HTML, with fields named, email, and website. I n the textarea field of the review, we put the script between the labels . T he PHP script outputs the $name, $email, $website, and $comment variables.

Then we also need to check the selected radio button, for which we must set the checked property (not the value property of the radio button):

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