Ryan Sanders;10908213 wrote:
$empty_fields = array();
Thats the first line.. I never use arrays. So when you are setting $empty_fields to array(); ... what exactly does that do? Just shows that its nothing?
This prepares the array for later use. It's just setting up some work space that I'm going to use later.
Ryan Sanders;10908213 wrote:
Then you have
$field_list = array('test', 'test2', test3');
foreach ($field_list as $field) {
I understand that part.. You are setting arrays for $field_list... like $field_list[1] would be test2. And I understand foreach.
Now this part:
if ($_POST[$field]=="") { $empty_fields[] = $field; }
When you use $empty_fields[] = $field
Does that really make $empty_fields[] --> $empty_fields[$field] or does it make it just $field??
remember that $empty_fields is the work space that I prepared earlier? Now I'm going to actually write something there.
$field is the name of whichever field I happen to be checking at the moment. So let's say it's our second time through the foreach loop. On our 2nd time through, $field is the the 2nd field in the list ("test2"). So I'm checking to see if:
$_POST['test2'] is blank.
if it is blank, then I am taking $field and adding it to the $empty_fields array.
So if the user leaves three fields blank, then when the foreach loop is finished, that array ($empty_fields) will have three values in it... the names of the 3 fields that they left blank.
Ryan Sanders;10908213 wrote:
And last:
if (count($empty_fields)) {
Basically.. you are counting and if there is anything posted to $empty_fields.. then that means there was a field empty. Or if count is true or equal to 1 or more.. then there was a field empty.
Is that abotu right?
Exactly. count() tells you the number of items in the array. If the user was a good little user, then count() will be zero and they can move right along. If count() has a value, then it was one or more, and they get the warning message.