Skip to content

[Form] getErrorsAsArray for Form class #7977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,27 @@ public function getErrorsAsString($level = 0)
return $errors;
}

/**
* Returns an array representation of all form errors (including children errors).
*
* @return array An array representation of all errors in a tree structure with field names as array keys
*/
public function getErrorsAsArray()
{
$errors = array();
foreach ($this->errors as $error) {
$errors[] = $error->getMessage();
}

foreach ($this->children as $key => $child) {
if ($err = $child->getErrorsAsArray()) {
$errors[$key] = $err;
}
}

return $errors;
}

/**
* {@inheritdoc}
*/
Expand Down