Jump to content

Problem with form validation for empty fields


Shadowing

Recommended Posts

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";



	}}}}}} 

Link to comment
Share on other sites

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"; 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.