Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $first_name = '';
- $last_name = '';
- $city = '';
- $error = false;
- if(isset($_POST['first_name'])) {
- $first_name = $_POST['first_name'];
- }
- if(isset($_POST['last_name'])) {
- $last_name = $_POST['last_name'];
- }
- if(isset($_POST['city'])) {
- $city = $_POST['city'];
- }
- ?>
- <style>
- h2 {
- font-size: 15px;
- color: green;
- }
- .error {
- background-color: red;
- padding: 10px;
- font-size: 20px;
- color: white;
- }
- .fields {
- padding: 10px;
- }
- .button{
- padding: 10px;
- margin: 10px;
- font-size: 20px;
- border-radius: 10px;
- }
- </style>
- <h1>My Final Project</h1>
- <hr />
- <form method="POST">
- <div class="fields">
- <label for="first_name">First Name *</label>
- <input type="text" value="<?php echo $first_name; ?>"
- name="first_name"
- required="required">
- <?php
- if(isset($_POST['first_name']) &&
- empty($_POST['first_name'])) {
- echo "<div class='error'>
- *You must fill in all fields*
- </div>";
- }?>
- </div>
- <div class="fields">
- <label for="last_name">Last Name *</label>
- <input type="text" value="<?php echo $last_name; ?>"
- name="last_name"
- required="required">
- <?php
- if(isset($_POST['last_name']) &&
- empty($_POST['last_name'])) {
- echo "<div class='error'>
- *You must fill in all fields*
- </div>";
- }
- ?>
- </div>
- <div class="fields">
- <label for="city">City *</label>
- <input type="text" value="<?php echo $city; ?>"
- name="city"
- required="required">
- <?php
- if(isset($_POST['city']) &&
- empty($_POST['city'])) {
- echo "<div class='error'>
- *You must fill in all fields*
- </div>";
- }
- ?>
- </div>
- <button class="button" type="submit">Submit</button>
- </form>
- <?php
- if($error = true) {
- } else {
- echo "<h2>Form Submitted Successfully</h2>";
- }
- print_r($_POST);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement