Posted By

onefastsnail on 05/24/12


Tagged


Versions (?)

validation


 / Published in: PHP
 

  1. if(isset($_POST["option"]) && $_POST["option"]=="submit"){
  2. $errors = array();
  3.  
  4. $required = array(
  5. "name" => "Please enter a name",
  6. "price" => "Please enter a price"
  7. );
  8.  
  9. foreach($required as $key => $value){
  10. if(trim($_POST[$key]=="")){
  11. $errors[] = $value;
  12. }
  13. }
  14.  
  15. if(sizeof($errors)<>0){ ?>
  16. <h2>Oops you have missed something...</h2>
  17. <ul class="error">
  18. <? foreach($errors as $error){ ?>
  19. <li><?=$error;?></li>
  20. <? }?>
  21. </ul>
  22. <? }
  23. else {
  24. //proceed
  25. }
  26.  
  27. }

Report this snippet  

You need to login to post a comment.