keyboarder Posted October 10, 2010 Share Posted October 10, 2010 (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted October 10, 2010 Share Posted October 10, 2010 This isn't doing what you think it is: if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ If $data_start is set (IE. if the user did input a start), !isset($data_start) will return FALSE. Therefor, if the user inputs a start date and/or an end date, your "if" is ignored (because you have FALSE && FALSE && TRUE && TRUE which equals FALSE which means: do not follow the "then" look for an "else"). What you want is: if (!empty($data_start) && !empty($data_end) && empty($pax) && empty($comment)) { Whenever possible, it's good to conditionalize the "accepted" input, and make the default action (if all the if statements are ignored) an error message. That way if there's a mistake in your if statements, the result will usually be an error message. 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.