function validate() { //Returns 'false' with no errors //Returns 'true' with errors $ERROR_Validate = false; $ERROR_Specify = array(); foreach($_POST as $a) { if ($a == "") { $ERROR_Validate = true; array_push($ERROR_Specify, "$a is empty!"; } } if($ERROR_Validate == false) { return false; } else { return array($ERROR_Specify); } }
OK all i want to do here is test for empty form inputs. its working fine. Then I wanted to make it report which inputs were missing and i cant quite figure out how. Above is what i had but I realise "array_push($ERROR_Specify, "$a is empty!";" is wrong. this will add > "is empty" < to the array.
I need to figure out how to get the correct key from the $_POST array when the element is empty. Also, running this script results in a error and im not sure why. commenting out the array_push line fixes it. I dont understand why.
Thanks for reading!
Im still learning php so youll have to forgive me for some silly mistakes!