mardi 24 novembre 2015

zf2 Checkbox rendering by formInput fails

I want to make a chekbox for terms of use. I've found an interesting solution, given by a webcoder How to validate a checkbox in ZF2

The case is that I have a difficult HTML structure, that's why I can't use neither formRow, nor formCollection to render. I'm trying to use the following approach instead:

$agreement = $form->get('agreement');
echo $this->formInput($agreement);
echo $this->formElementErrors($agreement);

And I receive the empty value:

input type="checkbox" name="agreement" class="checkbox" value=""

I also tried to add hidden field, but my attempt also failed:

$agreement = $form->get('agreement');
echo $this->formHidden($agreement);
echo $this->formInput($agreement);
echo $this->formElementErrors($agreement);

The html is:

input type="hidden" name="agreement" class="checkbox" value=""
input type="checkbox" name="agreement" class="checkbox" value=""

As a result I receive errors about "Value is required and can't be empty"

May be someone can give me a tip how to properly render checkbox in my case?




Aucun commentaire:

Enregistrer un commentaire