Get all symfony form errors


/ Published in: PHP
Save to your folder(s)

Add snippet in BaseFormPropel.class.php


Copy this code and paste it in your HTML
  1. public function getErrors()
  2. {
  3. $errors = array();
  4.  
  5. // individual widget errors
  6. foreach ($this as $form_field)
  7. {
  8. if ($form_field->hasError())
  9. {
  10. $error_obj = $form_field->getError();
  11. if ($error_obj instanceof sfValidatorErrorSchema)
  12. {
  13. foreach ($error_obj->getErrors() as $error)
  14. {
  15. // if a field has more than 1 error, it'll be over-written
  16. $errors[$form_field->getName()] = $error->getMessage();
  17. }
  18. }
  19. else
  20. {
  21. $errors[$form_field->getName()] = $error_obj->getMessage();
  22. }
  23. }
  24. }
  25.  
  26. // global errors
  27. foreach ($this->getGlobalErrors() as $validator_error)
  28. {
  29. $errors[] = $validator_error->getMessage();
  30. }
  31.  
  32. return $errors;
  33. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.