grippat Posted March 10, 2008 Share Posted March 10, 2008 I wrote a simple function to validate a form. All it does right now is take an associative array and go through it making sure each element has a value. If it doesn't it adds to the error array which it returns. For some reason the $field_name inside the loop doesn't contain anything. But if I do a print_r($entry) it gives me this: Array ( ['car'] => ['truck'] => ['bus'] => ['plane'] => ) And here's my function: // Validate entry form. function validateForm($entry) { $err = array(); foreach($entry as $field_name) { $field_name or $err[] = "Field $field_name is required."; } return $err; } Link to comment Share on other sites More sharing options...
Jesdisciple Posted March 10, 2008 Share Posted March 10, 2008 As I understand your function, you should change your foreach(click) to: . foreach($entry as $field_name => $field_value) { $field_value or $err[] = "Field $field_name is required."; } Link to comment Share on other sites More sharing options...
grippat Posted March 11, 2008 Author Share Posted March 11, 2008 Aha! That worked, thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.