Posted By

chopbust on 06/16/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

3polars


Server Side Form Validation


 / Published in: PHP
 

A generic loop-based form validation to check which _POST value is empty.

Enter the form name in Line 3 and put the description in Line 4.

  1. //---- validation ------ //
  2. $count = 0;
  3. $required_fields = array('name', 'id_no');
  4. $required_fields_description = array('Name of the user', 'Id');
  5.  
  6. //check all required forms
  7. foreach($required_fields as $fields) {
  8. if ($_POST[$fields] == "") $error_check .= "You need to enter field '".$required_fields_description[$count]."'. Go back. <br />";
  9. $count++;
  10. }
  11.  
  12. if ($error_check != "") die($error_check);
  13. //----- end validation ------//

Report this snippet  

You need to login to post a comment.