Skip to content

Instantly share code, notes, and snippets.

@ain
Created December 9, 2012 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ain/4245541 to your computer and use it in GitHub Desktop.
Save ain/4245541 to your computer and use it in GitHub Desktop.
Symfony 1.4 base form class with a method to output all errors of a Form in one array
<?php
class MyBaseForm extends sfFormSymfony
{
public function getErrors()
{
$errors = array();
foreach ($this as $form_field)
{
if ($form_field->hasError())
{
$error_obj = $form_field->getError();
if ($error_obj instanceof sfValidatorErrorSchema)
{
foreach ($error_obj->getErrors() as $error)
{
$errors[$form_field->getName()] = $error->getMessage();
}
}
else
{
$errors[$form_field->getName()] = $error_obj->getMessage();
}
}
}
foreach ($this->getGlobalErrors() as $validator_error)
{
$errors[] = $validator_error->getMessage();
}
return $errors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment