* Thus wrote Chris W. Parker ([EMAIL PROTECTED]): > Hey people. > > > function validateFormData($input) > { > foreach($input as $field) > { > switch ($field['type']) > { > case 'name': > // do the magic > break; > case 'phonenumber': > // do the magic > break; > } > } > } > > > The validateFormData() function will return false if there are no errors > to report.
I usually return an empty array. > > For a form that has a lot of fields to validate I think this can make > things pretty easy. > > > So... what do you think? I do this very exact thing in a lot of my code. The validation function's are usually related to the object I'm validating. function customer_info_validate($customer); Then you can take it a step further and make some generic common validation's like email, phone numbers, etc and your magic code would just call those. Then make a generic function that accepts a value and a regex pattern to validate against the value. So now your switch would be something like: case 'name': validate_regex($field['value'], '/^[a-z ]{5,50}$/i'); break; case 'us_phone': validate_us_phone($field['value']); break; etc.. Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php