Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <head>
- <title>Form validation </title>
- </head>
- <body>
- <?php
- if (isset($_POST['submit'])) {
- ////////////////////////////////////////////////////////////////////
- //checking names
- ///////////////////////////////////////////////////////////////////
- if(empty($_POST['fname']))
- $msg_fname = "You must supply your forname";
- $fname_sub = $_POST['fname'];
- $regexf = '/^[a-zA-Z ]*$/';
- preg_match($regexf, $fname_sub, $fname_matches);
- if(!$fname_matches[o])
- $msg2_fname = "please check forname";
- ///////////////////////////////////////////////////////////////////
- if(empty($_POST['lname']))
- $msg_lname = "You must supply your surname";
- $lname_sub = $_POST['lname'];
- $regexl= '/^[a-zA-Z ]*$/';
- preg_match($regexl, $lname_sub, $lname_matches);
- if(!$lname_matches[o])
- $msg2_lname = "please check surname";
- ////////////////////////////////////////////////////////////////////
- //check email
- ////////////////////////////////////////////////////////////////////
- if(empty($_POST['email']))
- $msg_email = "You must supply your email";
- $email_sub = $_POST['email'];
- $email_pattern = '/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/';
- preg_match($email_pattern, $email_sub, $email_matches);
- if(!$email_matches[0])
- $msg2_email = "Must be of valid email format";
- }
- ?>
- <?php
- // validation complete
- if(isset($_POST['submit'])){
- if($msg_fname=="fname" && $msg2_fname=="fname" && $msg_lname=="lname" && $msg2_lname=="lname" && $msg_email=="" && $msg2_email=="");
- $msg_success = "You filled this form up correctly";
- }
- ?>
- <div class="container">
- <?php echo "<h3 class='success_msg'>".$msg_success."</h3>"; ?>
- <form id="registration_form" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- <label>Forename<span class="note">*</span>:</label>
- <input type="text" name="fname" value="<?php echo $_POST['fname']; ?>">
- <?php echo "<p class='note'>".$msg_fname."</p>";?>
- <?php //echo "<p class='note'>".$msg2_fname."</p>";?>
- <label>Surname<span class="note">*</span>:</label>
- <input type="text" name="lname" value="<?php echo $_POST['lname']; ?>">
- <?php echo "<p class='note'>".$msg_lname."</p>";?>
- <?php //echo "<p class='note'>".$msg2_lname."</p>";?>
- <label>Email address<span class="note">*</span>:</label>
- <input type="text" name="email" value="<?php echo $_POST['email']; ?>">
- <?php echo "<p class='note'>".$msg_email."</p>";?>
- <?php echo "<p class='note'>".$msg2_email."</p>";?>
- <button type="submit" class="" name="submit">send</button>
- </form>
- </div>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement