forms - Redirect to new page after PHP validation -
i new php , have been working on website contains form restaurant reservation. currently, have 1 file, contains both html , php code. form validated once user clicks submit, wondering how might possible redirect user new page, confirming reservation, if of information have entered form correct.
basically process wish website perform:
user fills out form if validation not complete display error messages, loop form user can correct fields if form validated send user confirmation page
here necessary code reservations page:
.... <?php $nameerr = $teleerr = $emailerr = $partyerr = $viperr = $reservationerr = $timeerr = ""; $name = $tele = $email = $party = $vip = $reservation = $time = ""; if ($_server["request_method"] == "post") { if (empty($_post["name"])) { $nameerr = "please enter full name"; } else { $name = test_input($_post["name"]); if (!preg_match("/^[a-za-z ]*$/",$name)) { $nameerr = "invalid name entered"; } } if (empty($_post["tele"])) { $teleerr = "please enter telephone number"; } else { $tele = test_input($_post["tele"]); if (!preg_match("/^[0-9 ]{7,}$/",$tele)) { $teleerr = "invalid telephone number entered"; } } if (empty($_post["email"])) { $emailerr = "please enter email address"; } else { $email = test_input($_post["email"]); if (!filter_var($email, filter_validate_email)) { $emailerr = "invalid email entered"; } } if($_post['party']=="") { $partyerr = "please select party size"; } else { $party = test_input($_post["party"]); } if (empty($_post["vip"])) { $viperr = "please make vip area selection"; } else { $vip = test_input($_post["vip"]); } if (empty($_post["reservation"])) { $reservationerr = "please enter reservation date"; } else { $reservation = test_input($_post["reservation"]); if (!preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/",$reservation)) { $reservationerr = "invalid reservation date"; } } if($_post['time']=="") { $timeerr = "please select reservation time"; } else { $time = test_input($_post["time"]); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } ?> <body> <div id= "container"> <div id="header"> <div id="logo"> <img src="steakhouselogo.png" width="440" height="152" alt="this image of steakhouse® logo"> </div> <br> <p class="slogan"> <strong> welcome steakhouse®, number 1 restaurant flame grilled goodness. </strong> </p> </div> <div id="links"> <ul class="nav"> </ul> </div> <br> <!-- introduction of html form --> <div id="body"> <h1> book table </h1> <br><br> <br> <div class="view"> <img src="view.png" width="451" height="227" alt="a view of our restaurant"> </div> <br> <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>"> <!-- personal information --> <div class="form"> <div class="indicates"> <br> * indicates required field </div> <p class="ex"> <br><br> <strong> full name* : </strong> <br> <input type="text" placeholder="john doe" name="name" value="<?php echo $name;?>"> <span class="error"> <?php echo $nameerr;?></span> <br><br><br> <strong> contact telephone* : </strong> <br> <input type="text" placeholder="telephone number" name="tele" value="<?php echo $tele;?>"> <span class="error"><?php echo $teleerr;?></span> <br><br><br> <strong> contact email* : </strong> <br> <input type="text" placeholder="example@email.com" name="email" value="<?php echo $email;?>"> <span class="error"><?php echo $emailerr;?></span> <br><br> <!-- party requirments --> <br> <strong>select party size* :</strong> <br> <select name="party" id="party" value="<?php echo $party;?>"> <option value="">please select</option> <option <?php if (isset($party) && $party=="5") echo "selected";?> value="5">1 person (+£5)</option> <option <?php if (isset($party) && $party=="10") echo "selected";?> value="10">2 people (+£10)</option> <option <?php if (isset($party) && $party=="15") echo "selected";?> value="15">3 people (+£15)</option> <option <?php if (isset($party) && $party=="20") echo "selected";?> value="20">4 people (+£20)</option> <option <?php if (isset($party) && $party=="25") echo "selected";?> value="25">5 people (+£25)</option> <option <?php if (isset($party) && $party=="30") echo "selected";?> value="30">6 people (+£30)</option> <option <?php if (isset($party) && $party=="35") echo "selected";?> value="35">7 people (+£35)</option> <option <?php if (isset($party) && $party=="40") echo "selected";?> value="40">8 people (+£40)</option> <option <?php if (isset($party) && $party=="45") echo "selected";?> value="45">9 people (+£45)</option> <option <?php if (isset($party) && $party=="50") echo "selected";?> value="50">10+ people (+£50)</option> </select> <span id="party" class="error"><?php echo $partyerr;?></span> <br><br><br> <strong>dietary requirements:</strong> <br><br> vegetarian <input type="checkbox" name="diet[]" value="vegetarian"> <br><br> vegan <input type="checkbox" name="diet[]" value="vegan"> <br><br> peanut allergy <input type="checkbox" name="diet[]" value="peanut allergy"> <br><br> gluten allergy <input type="checkbox" name="diet[]" value="gluten allergy"> <br><br><br> <strong> vip area* : </strong> <br><br> yes (+£5) <input type="radio" name="vip" <?php if (isset($vip) && $vip=="yes") echo "checked";?> value="yes"> <br><span id="vip" class="error"><?php echo $viperr;?></span><br> no <input type="radio" name="vip" <?php if (isset($vip) && $vip=="no") echo "checked";?> value="no"> <br><br><br> <strong> reservation date* : </strong> <br> <input type="text" placeholder="dd/mm/yyyy" name="reservation" value="<?php echo $reservation;?>"> <span class="error"><?php echo $reservationerr;?></span> <br><br><br> <strong> reservation time* : </strong> <br> <select name="time" value="<?php echo $time;?>"> <option value="">please select</option> <option <?php if (isset($time) && $time=="17:00") echo "selected";?> value="17:00">17:00</option> <option <?php if (isset($time) && $time=="17:30") echo "selected";?> value="17:30">17:30</option> <option <?php if (isset($time) && $time=="18:00") echo "selected";?> value="18:00">18:00</option> <option <?php if (isset($time) && $time=="18:30") echo "selected";?> value="18:30">18:30</option> <option <?php if (isset($time) && $time=="19:00") echo "selected";?> value="19:00">19:00</option> <option <?php if (isset($time) && $time=="19:30") echo "selected";?> value="19:30">19:30</option> <option <?php if (isset($time) && $time=="20:00") echo "selected";?> value="20:00">20:00</option> <option <?php if (isset($time) && $time=="20:30") echo "selected";?> value="20:30">20:30</option> <option <?php if (isset($time) && $time=="21:00") echo "selected";?> value="21:00">21:00</option> <option <?php if (isset($time) && $time=="21:30") echo "selected";?> value="21:30">21:30</option> <option <?php if (isset($time) && $time=="22:00") echo "selected";?> value="22:00">22:00</option> </select> <span id="time" class="error"><?php echo $timeerr;?></span> <br><br><br> <strong> additional information: </strong> <br> <textarea name="comments" placeholder="birthdays, class parties..." rows="7" cols="40"></textarea> <br><br> <div class="totalprice"> total reservation price calculated automatically once submitted. <br><br><br> </div> <div class="submitetc"> <input type="submit" id="submit" name="submit" value="submit"> <input type="reset" value="reset form"> <br><br><br><br> ....
i have put lot of effort work far, suggestions welcomed. please remember new web languages also. thank you.
here code
<?php $nameerr = $teleerr = $emailerr = $partyerr = $viperr = $reservationerr = $timeerr = ""; $name = $tele = $email = $party = $vip = $reservation = $time = ""; if ($_server["request_method"] == "post") { if (empty($_post["name"])) { $nameerr = "please enter full name"; } else { $name = test_input($_post["name"]); if (!preg_match("/^[a-za-z ]*$/",$name)) { $nameerr = "invalid name entered"; } } if (empty($_post["tele"])) { $teleerr = "please enter telephone number"; } else { $tele = test_input($_post["tele"]); if (!preg_match("/^[0-9 ]{7,}$/",$tele)) { $teleerr = "invalid telephone number entered"; } } if (empty($_post["email"])) { $emailerr = "please enter email address"; } else { $email = test_input($_post["email"]); if (!filter_var($email, filter_validate_email)) { $emailerr = "invalid email entered"; } } if($_post['party']=="") { $partyerr = "please select party size"; } else { $party = test_input($_post["party"]); } if (empty($_post["vip"])) { $viperr = "please make vip area selection"; } else { $vip = test_input($_post["vip"]); } if (empty($_post["reservation"])) { $reservationerr = "please enter reservation date"; } else { $reservation = test_input($_post["reservation"]); if (!preg_match("/^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/",$reservation)) { $reservationerr = "invalid reservation date"; } } if($_post['time']=="") { $timeerr = "please select reservation time"; } else { $time = test_input($_post["time"]); } if($nameerr == "" && $teleerr == "" && $emailerr == "" && $partyerr == "" && $viperr == "" && $reservationerr == "" && $timeerr == ""){ header('location: http://yoursite.com/dashboard'); exit(); } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; }
?>
Comments
Post a Comment