why
why

Reputation: 195

Zend Form - problem rendering individual elements

I have this simplified form:

        $this->form = new \Zend_Form();
        $this->form->setAction($request->currentPath());
        $this->form->setMethod('post');


        $this->form->addElement('text', 'firstName', array(
            'label' => 'First name: ',
        ));

and I want to render the element individually in my view page. Like so:

        <?php echo $form->firstName->renderViewHelper() ?>

But I keep getting this error:

Fatal error: Uncaught exception 'Zend_Form_Decorator_Exception' with message 'ViewHelper decorator cannot render without a registered view object'.

What am I doing wrong? I have pretty much followed the Zend Documentation on this page: http://framework.zend.com/manual/en/learning.form.decorators.individual.html

Sincerely, Why

Upvotes: 1

Views: 3506

Answers (1)

DarkLeafyGreen
DarkLeafyGreen

Reputation: 70416

You need to pass the form object after creating it in one of your controllers to your view script to render the form elements.

$this->view->form = $form;

And in your view script do something like

echo $this->form->firstName->renderViewHelper();

Upvotes: 3

Related Questions