After numerous of experiments because I had some issues caused by â€œbugâ€ in Zend Framework Zend_Form_Element_Checkbox which prevents a selected checkbox to be submitted I finally was able to create a working Zend_Form_Element_Checkbox, below you will see the exact code of the working code which I create within a subform and does the trick of an Accept Agreement checkbox field which is a perfect suit for a Registration Form being prepared with ZF.
$risk_statement_full = 'something';
$accept_disclaimer = new Zend_Form_SubForm();
$disclaimer = new Zend_Form_Element_Checkbox(‘accept_disclaimer’, array(
‘label’ > “$risk_statement_full”,
‘description’ > $accept_disclaimerOptions,
‘uncheckedvalue’ > ”,
‘checkedvalue’ > ‘1’,
‘value’ > 1,
‘required’ > true,
I have to express my thanks to a bunch of guys who gave me big help in irc.freenode.net in #zftalk â€“ which by the way is the official Zend Framework IRC Channel.
The guy that helped the most was with a nickname Bittarman thanks man!
The solution to the * Value is required and canâ€™t be empty error message which appeared all the time nomatter if the form checkbox is selected or not was through using the Zend_Form_Element_Checkbox options:
â€˜uncheckedvalueâ€™ => â€
â€˜checkedvalueâ€™ => â€™1â€²
there is also a separate Zend Methods to be used like so:
This stupidity took me like 2 hours of googling and testing â€¦ finally though the above solution worked for me it appeared like non-working because my Iceweasel browser has cached the webpage â€¦ If you still canâ€™t solve the issue using the above solution, cleanse your browser cache!