jayjay76 Posted October 14, 2007 Share Posted October 14, 2007 I'm having trouble making a couple different types of fields on a <FORM> work -- when the form is processed, I have 2 types of fields I am trying to ensure the person clicks. If they don't fill out or click the appropriate field, the web page should notify them of this. name and address are simple fields where a person fills that in. ordertype is one of two radio buttons a person clicks on. I am detecting the fields that need to be populated, but cannot seem to detect when a radio button is not clicked on. What I have right now in the php form processor: $name = $_POST['name']; $address = $_POST['address']; $order = $_POST['ordertype']; if(empty($name) || empty($address)) { echo "Please fill in all required fields.\n"; } if(empty($order)) { echo "Please click on an order type.\n"; } The second check for $order never seems to get processed for some reason. Alternatively, is there a good PHP way to check to see that a field is populated and if not, create a popup tiny window that alerts the person that they need to populate such and such a field instsead of giving them a blank webpage as above and requiring them to click on the back arrow of the browser? Any examples would be excellent. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/73206-multiple-required-fields/ Share on other sites More sharing options...
kratsg Posted October 14, 2007 Share Posted October 14, 2007 $name = $_POST['name']; $address = $_POST['address']; $order = $_POST['ordertype']; Try this instead: <?php $error = "We have detected an error. Please fix the following:<br>"; $error_check = 0; if(!isset($_POST['name')){//doesn't exist $error .= "<br>No name has been filled in."; $error_check++; } if(!isset($_POST['address'])){//doesn't exist $error .= "<br>No address has been filled in."; $error_check++; } if(!isset($_POST['ordertype']){//doesn't exist $error .= "<br>No radio button has been selected."; $error_check++; } if($error_check != 0){ die($error); } else {//everything is a-ok. return true; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73206-multiple-required-fields/#findComment-369299 Share on other sites More sharing options...
jayjay76 Posted October 15, 2007 Author Share Posted October 15, 2007 The posted code is returning a blank page for some reason. Here is what I have -- not sure why it's blank as I cannot see an error in here: <?php $name = $_POST['name']; $address = $_POST['address']; $order = $_POST['ordertype']; if (eregi('http:', $comment)) { die ("No URLs are allowed in these fields!"); } $error = "We have detected an error. Please fix the following:<br>"; $error_check = 0; if(!isset($_POST['name')){//doesn't exist $error .= "<br>No name has been filled in."; $error_check++; } if(!isset($_POST['address'])){//doesn't exist $error .= "<br>No address has been filled in."; $error_check++; } if(!isset($_POST['ordertype']){//doesn't exist $error .= "<br>No radio button has been selected."; $error_check++; } if($error_check != 0){ die($error); } else {//everything is a-ok. return true; } // email results and send customer to "Thank You" page. ?> Quote Link to comment https://forums.phpfreaks.com/topic/73206-multiple-required-fields/#findComment-369846 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.