Paladyn wrote
> Is there a way to add checkbox (or other) elements in form constructor
> like this:
>
> $this->add(array(
> 'name' => 'checkbox',
> 'attributes' => array(
> 'type' => 'checkbox',
> ),
> 'options' => array(
> 'label' => 'CheckBox',
> ),
> ));
>
> After using echo $this->formCheckbox($form->get('checkbox'));
>
> In view I`m getting error: Fatal error: Uncaught exception
> 'Zend\Form\Exception\InvalidArgumentException' with message
> 'Zend\Form\View\Helper\FormCheckbox::render requires that the element is
> of type Zend\Form\Element\Checkbox'
>
> So $this->add is`t creating right object based on attributes->type.
>
> Of course everything works right after this way:
>
> $checkbox = new Element\Checkbox('checkbox');
> $checkbox->setLabel('CheckBox');
>
> $this->add($checkbox);
>
> But first way seems a bit faster for me (If it would be working).
You're setting wrong keys, try this:
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'Name',
'options' => array(
'label' => 'Name:',
'class' => 'cssClass',
//'value_options' => array('man'=>1,'woman'=>2)
),
));
-----
Cheers,
--
Luke Mierzwa
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Zend-Form-Checkbox-in-Form-constructor-tp4657206p4657207.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]