This works. I've adapted this from a form I'm using so I stuck in a few other things like ID's that you can use if you like. Useful to see how it all comes together anyway:
In my controller:
private function _theForm() {
$form = new Zend_Form;
$form->setAction('/controller/action')
->setMethod('post')
->addAttribs(array('id' => 'an_id_for_the_form'));
$form->addElement('text', 'start', array(
'validators' => array(
'NotEmpty'
),
'label' => 'Start:',
'id' => 'someid',
'required' => true,
'decorators' => array(
'ViewHelper',
'Errors',
'Label',
),
));
$form->addElement('text', 'end', array(
'validators' => array(
'NotEmpty'
),
'label' => 'End:',
'id' => 'someotherid_if_you_like',
'required' => true,
'decorators' => array(
'ViewHelper',
'Errors',
'Label',
),
));
$form->addElement('submit', 'submitSomething', array(
'label' => 'Submit',
'decorators' => array(
'ViewHelper',
)
));
$form->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'p', 'id' => 'foo')),
'Form',
));
return $form;
}
I then call that elsewhere in my controller, like:
$form = $this->_theForm();
$this->view->form = $form;
Then you can use it in your view like:
<?php echo $this->form; ?>