Skip to content

Instantly share code, notes, and snippets.

@b-b3rn4rd
Created October 3, 2013 06:31
Show Gist options
  • Save b-b3rn4rd/6805880 to your computer and use it in GitHub Desktop.
Save b-b3rn4rd/6805880 to your computer and use it in GitHub Desktop.
Get flatten Zend_Form error messages
<?php
class My_Form extends \Zend_Form
{
/**
* Flatten Zend_Form error messages
*
* @param \Zend_Form|null $form
* @param array|null $messages
* @param int $i
* @return array
*/
public function getMessagesSimple(\Zend_Form $form = null, array $messages = null, &$i = 0)
{
$return = array();
if (is_null($form)) {
$form = $this;
$messages = parent::getMessages();
}
foreach ($messages as $fieldname => $errors) {
$subForm = $form->getSubForm($fieldname);
if ($subForm instanceof \Zend_Form) {
$return += $this->getMessagesSimple($subForm, $errors, $i);
continue;
}
foreach ($errors as $name => $value) {
$element = $form->getElement($fieldname);
$label = $element->getLabel();
$return[$i] = array(
'message' => $value,
'label' => $label,
'fieldname' => $fieldname);
$i++;
}
}
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment