Shadowing Posted January 22, 2012 Share Posted January 22, 2012 I dont understand why this simple validation im doing isnt working. I got rid of all my code and took it down to its simpliest form. I tried every debuging i can think of using echo's. If all fields are blank it performs as suspected and echos all fields are empty. but if i type something in one of the fields or all the fields at once it never goes onto the else statment. Is it possible to display everything a page is doing? in like true and false statements. if (isset($_POST['send_attack'])) { // checks if all fields are blank if(empty($_POST['jaffa'])) { echo "jaffa is empty <br />"; if(empty($_POST['staff_cannons'])) { echo "staff_cannons is empty <br />"; if(empty($_POST['transport_ships'])) { echo "transport_ships is empty <br />"; if(empty($_POST['bombers'])) { echo "bombers is empty <br />"; if(empty($_POST['mother_ships'])) { echo "mother_ships is empty <br />"; echo "all fields are empty"; }else{ echo "one or more fields has something in it"; }}}}}} Quote Link to comment https://forums.phpfreaks.com/topic/255525-problem-with-form-validation-for-empty-fields/ Share on other sites More sharing options...
Pikachu2000 Posted January 22, 2012 Share Posted January 22, 2012 Why do you have all of those if() conditionals nested like that? Format and indent your code properly, then look carefully at the logic of how it works. It should be obvious at that point. Quote Link to comment https://forums.phpfreaks.com/topic/255525-problem-with-form-validation-for-empty-fields/#findComment-1310076 Share on other sites More sharing options...
Shadowing Posted January 22, 2012 Author Share Posted January 22, 2012 I figured out whats going on lol. I guess ive never came across a statement that I needed like this one before. The code stops in the first field that has something in it. I dont know why I thought it would keep reading. So the statement wasnt saying anything like I thought it was. Im wanting the statement to read. If all fields are empty at once echo "all fields are empty" other wise proceed. what i had it was just checking the condition then stoping if it was false. So i needed to combine the if statment with && if(empty($_POST['jaffa']) && empty($_POST['staff_cannons']) && empty($_POST['transport_ships']) && empty($_POST['bombers']) && empty($_POST['mother_ships'])) { echo "all fields are empty"; }else{ echo "continue"; Quote Link to comment https://forums.phpfreaks.com/topic/255525-problem-with-form-validation-for-empty-fields/#findComment-1310097 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.