php

PHP Form Complete


 

PHP - Keep the Values in The Form


To display the values entered by the user in input fields after hitting the submit button, you can use a bit of PHP within the HTML form. Here's an example with input fields for name, email.


Certainly! If you want to display which radio button was checked after the form is submitted, we can manipulate the checked attribute for radio buttons.
 

Code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Form Complete</title>
</head>
<body>
    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
</body>
</html>

 

OUTPUT: