Полный контроль над выводом формы без обхода логики / фильтрации / проверки формы The View:</p>
<pre><code><form action="<?php echo $this->form->getAction(); ?>" method="<?php echo $this->form->getMethod(); ?>">
<!-- Errors For question field-->
<?php echo (NULL != ($errors = $this->form->getElement('question')->getMessages()) ? $this->formErrors($errors) : ''); ?>
<!-- question field -->
<?php echo $this->form->getElement('question')->renderViewHelper(); ?>
<!-- Submit Field -->
<?php echo $this->form->getElement('submit')->renderViewHelper(); ?>
</form>
Конец
The Form</p>
<pre><code><?php
class Form_Question extends Zend_Form
{
public function init()
{
$this->setMethod(self::METHOD_POST);
$element = $this->createElement('text', 'question');
$element->setLabel('Question');
$element->setRequired(TRUE);
$element->removeDecorator('DtDdWrapper');
$element->setAttrib('class', 'text');
$this->addElement($element);
$element = $this->createElement('submit', 'submit');
$element->setLabel('Submit');
$element->setRequired(TRUE);
$element->removeDecorator('DtDdWrapper');
$element->removeDecorator('label');
$this->addElement($element);
}
}
конец формы
the controller action</p>
<pre><code> public function questionAction()
{
$form = new Form_Question();
if($this->getRequest()->isPost())
{
if($form->isValid($this->getRequest()->getPost()))
{
// Do stuff
}
else
{
$this->_helper->FlashMessenger(array('error' => "Errors! Correct the errors in the form below"));
}
}
$this->view->assign('form', $form);
}
действие конечного контроллера