Ways of rendering your form in Zf2

  • Form collection will render all your elements, including error notification.
$form = $this->form;
echo $this->formCollection($form);
  • It will render the label, input field and error notification.
    $form = $this->form;
    echo $this->formRow($form->get('ElementName'));
  • Very useful for custom display of your form but you need to do it 1 by 1 for each form element.
    $form = $this->form;
    echo $this->formLabel($form->get('ElementName')); //display label
    echo $this->formInput($form->get('ElementName')); //display input
    echo $this->formElementErrors($form->get('ElementName'), array(
         'class' => 'text-error')); //display error

Leave a Reply