2
votes

Is there a tutorial on how to use "zend form" without the whole framework ?

I'm using Zend Framework 2. I manage to use Zend\Config\Reader\Ini to read the configuration and pass the config to Zend\Form\Factory using "fromFile()" method, but after that I don't even know how to render the form. I use "Twig" for my template engine so I need to output the form I create to Twig token.

The way to do it change drastically from Zend Framework 1 and I check the tutorial it only show the way to do it when you use their full mvc framework .

Can anyone help ?

In Zend Framework 1 I remember we just do it like this

$form = new Zend_Form(new Zend_Config_Ini('some_config.ini');
$form->render (new Zend_View());

What is the equivalent/similar method for Zend Framework 2 ?

1

1 Answers

0
votes

It's different in zf2, instead of one render() call as in zf1, now you have to echo each form element and the form's open and close tag in your view script. So, in your controller:

$form = new \Zend\Form\Form;
$form->append(new \Zend\Form\Element\Email('email'));
return new ViewModel(array('form' => $form));

and in your view script:

echo $this->form()->openTag($form);
foreach ($form as $element)
       echo $this->formRow($element);
echo $this->form()->openTag($form);