mermyphp Posted December 12, 2009 Share Posted December 12, 2009 I have an order form script, and when a user does not fill out a field, it shows an error message on a new page... one at a time. For example, if you forgot to fill in your email, and your name, it would show "please fill in your name Go Back". Then you fill in your name, and resubmit, it will say "please fill in your email Go Back", and so on. I would like to be able to list all the required fields at once when a user forgets to fill them in. Here is my current code: <?php /* Set e-mail recipient */ $myemail = "support@zip-cover.com"; /* Check all form inputs using check_input function */ $subject = check_input($_POST['subject'], "Please enter your name"); $email = check_input($_POST['email'], "Please enter your email"); $phone = check_input($_POST['phone']); $street = check_input($_POST['street'], "Please enter your street address"); $city = check_input($_POST['city'], "Please enter your city"); $state = check_input($_POST['state'], "Please enter your state/province"); $country = check_input($_POST['country'], "Please enter your country"); $postal = check_input($_POST['postal'], "Please enter your zip code"); $Manufacturer = check_input($_POST['Manufacturer'], "Please enter your boat manufacturer"); $Year = check_input($_POST['Year']); $BoatClass = check_input($_POST['BoatClass'], "Please choose your boat class"); $BoatModel = check_input($_POST['BoatModel'], "Please choose your boat model"); $CoverModel = check_input($_POST['CoverModel']); $CoverQuantity = check_input($_POST['CoverQuantity']); $CoverBoatModel = check_input($_POST['CoverBoatModel']); $RigQuantity = check_input($_POST['RigQuantity']); $Fabric = check_input($_POST['Fabric']); $OarBag = check_input($_POST['OarBag']); $MainColor = check_input($_POST['MainColorN']); $TipColor = check_input($_POST['TipColorN']); $MainColor = check_input($_POST['MainColorP']); $TipColor = check_input($_POST['TipColorP']); $MainColor = check_input($_POST['MainColorS']); $TipColor = check_input($_POST['TipColorS']); $requests = check_input($_POST['requests']); $how = check_input($_POST['how']); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $message = "Zip-Cover.com order form From: $subject $email $phone Shipping Address: $street $city, $state $country $postal Boat Type Manufacturer: $Manufacturer Year Built: $Year Boat Class: $BoatClass Boat Model: $BoatModel Quantity Product $CoverQuantity of $CoverModel $RigQuantity of Rigger Bag $OarQuantity of Oar Bag Fabric $Fabric Colors- Make sure colors corrospond to fabric choice. Ignore any other colors. Nylon Main Color: $MainColorN Nylon Tip Color: $TipColorN Polyester Main Color: $MainColorP Polyester Tip Color: $TipColorP Sunbrella Main Color: $MainColorS Sunbrella Tip Color: $TipColorS Special Requests $requests How They Found Us: $how zip-cover.com "; /* Send the message using mail() function */ mail($myemail, $subject, $message, "From: $email"); /* Redirect visitor to the thank you page */ header('Location: recieves.html'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <b>Fields with red astericks are required. <br />Please correct the following error:</b><br /> <?php echo $myError; ?><br /> <a href="javascript:history.go(-1)">Go back</a> </body> </html> <?php exit(); } ?> Any help would be appreciated greatly. Thanks in advance, mermyphp Quote Link to comment https://forums.phpfreaks.com/topic/184900-php-form-error-list/ Share on other sites More sharing options...
mikesta707 Posted December 12, 2009 Share Posted December 12, 2009 well first off all, your show_error() function <html> <body> <b>Fields with red astericks are required. <br />Please correct the following error:</b><br /> <?php echo $myError; ?><br /> <a href="javascript:history.go(-1)">Go back</a> </body> </html> You should leave out the html/body tags. First off, if you have multiple errors (which you might) you will have multiple html/body tags, which not only is invalid html, but will prevent you from seeing other stuff (because the main body tags, which are the first that appear, have been closed). Quote Link to comment https://forums.phpfreaks.com/topic/184900-php-form-error-list/#findComment-976080 Share on other sites More sharing options...
mermyphp Posted December 12, 2009 Author Share Posted December 12, 2009 Ugh.. Didn't make a difference Quote Link to comment https://forums.phpfreaks.com/topic/184900-php-form-error-list/#findComment-976081 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 take out the exit statement and if that doesnt work post your new code. Quote Link to comment https://forums.phpfreaks.com/topic/184900-php-form-error-list/#findComment-976091 Share on other sites More sharing options...
mermyphp Posted December 12, 2009 Author Share Posted December 12, 2009 THANK YOU!!!!! :D :D :D Quote Link to comment https://forums.phpfreaks.com/topic/184900-php-form-error-list/#findComment-976107 Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 Just so you know the exit() function ends script processing which is why it was stopping. Also if this is solved mark it as so. Quote Link to comment https://forums.phpfreaks.com/topic/184900-php-form-error-list/#findComment-976109 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.