Issues

ZF2-457: Fatal error: Call to undefined method Zend\Form\Element::getCheckedValue() in Zend\Form\View\Helper\FormCheckbox.php on line 48

Description

Got the error shown in Summary when using the formCheckbox helper to render a checkbox. Tested against zendframework-zf2-release-2.0.0rc2-86-g8fb1930


// sample form
namespace Web\Form;
use Zend\Form\Form;
class Test extends Form
{
    public function __construct($name = null)
    {
        parent::__construct($name);

        $this->setAttribute('method', 'post');

        $this->add(array(
            'name' => 'testcheck',
            'attributes' => array(
                'type' => 'checkbox',
                'checked' => false,
            ),
            'options' => array(
                'label' => 'Test option',
            ),
        ));
    }
}

// sample controller
public testAction()
{
    $form = new \Web\Form\Test();
    return array('form' => $form);
}

// sample view script
<?php echo $this->formCheckbox($form->get('testcheck')); ?>

Comments

The formCheckbox helper requires that the Element is of type Zend\Form\Element\Checkbox in order to get extra information for rendering the checkbox (checked, unchecked, useHiddenElement values).

Added PR to ensure that Checkbox Element is used: https://github.com/zendframework/zf2/pull/2156

Downgrading issue from Blocker to Major since there is a workaround via Zend\Form\Element\Checkbox.

Patch merged