Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP script GetFormData.php which retrieves the input data from an HTML form, and displays it as string.
- The input fields should hold name, age and gender (radio buttons). The returned string should be a message
- containing the information submitted by the form. 100% accuracy is NOT required. Semantic HTML is required.-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta content="text/html" charset="UTF-8">
- <title>Form Data</title>
- <style type="text/css">
- form {
- margin-bottom: 15px;
- }
- p {
- padding: 2px;
- margin: 0;
- }
- </style>
- </head>
- <body>
- <form action="#" method="post">
- <p><input type="text" name="username" maxlength="25" placeholder="Name..." required/></p>
- <p><input type="number" name="age" min="1" max="100" placeholder="Age..." required/></p>
- <p><input type="radio" name="gender" value="male" id="gender-male" checked="checked"/><label
- for="gender-male">Male</label></p>
- <p><input type="radio" name="gender" value="female" id="gender-female"/><label
- for="gender-female">Female</label></p>
- <input type="submit" value="Submit"/>
- </form>
- <?php
- mb_internal_encoding("UTF-8");
- if (count($_POST) == 3) {
- $username = trim($_POST['username']);
- $age = $_POST['age'];
- $gender = $_POST['gender'];
- echo '<p>My name is ' . htmlspecialchars($username) . '. I am ' . htmlspecialchars($age) .
- ' years old. I am ' . htmlspecialchars($gender) . ".</p>\n";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement