virtual Posted April 30, 2010 Report Share Posted April 30, 2010 I am trying to put a required field for the $children field into an email reservation form. However if I enter 0 in this field I get an error message, any other number or text is fine, but if the guests don't have kids, I don't want to show an error. How do I get the PHP script to accept 0 as a valid answer? Help will be much appreciated. Here is the script: <?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $adults = $_POST['adults']; $children = $_POST['children']; $age = $_POST['age']; $notes = $_POST['notes']; $attn = $_POST['attn']; if (eregi('http:', $notes)) { die ("Do NOT try that! ! "); } if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) { echo "<h2>Please use browser Back button - Enter valid e-mail</h2>\n"; $badinput = "<h2>Your email was NOT submitted</h2>\n"; echo $badinput; die (); } if(empty($visitor) || empty($visitormail) || empty($adults) || empty($children) || empty($notes )) { echo "<h2>Please use browser Back button - Fill in all fields</h2>\n"; die (); } $todayis = date("l, F j, Y, g:i a") ; $notes = stripcslashes($notes); $message = " $todayis [EST] \n Phone: $phone \n Message: $notes \n From: $visitor ($visitormail)\n Additional Info : IP = $ip \n Referral : $httpref \n "; $from = "From: $visitormail\r\n"; mail("me@atmysite.com", $subject, $message, $from); ?> <p align="center"> Date: <?php echo $todayis ?> <br /> Thank you <?php echo $visitor ?> for your message, we will contact you shortly. <br /> <br /> Message:<br /> <?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?> <br /> <?php echo $ip ?> Quote Link to comment Share on other sites More sharing options...
falkencreative Posted May 1, 2010 Report Share Posted May 1, 2010 Rather than using empty() try using if ($variable == '') I believe that the 0 is being interpreted as "false" rather than the number 0. Quote Link to comment Share on other sites More sharing options...
virtual Posted May 1, 2010 Author Report Share Posted May 1, 2010 Wonderful, so simple and worked like a charm. Thanks once again Ben. Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.