Archive for July 16th, 2010

Create a license agreement accept form checkout field within a Subform with Zend Framework

Friday, July 16th, 2010

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_disclaimerOptions='I accept';
$accept_disclaimer = new Zend_Form_SubForm();
$accept_disclaimer>addElements(array(

$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’ => ”
and
‘checkedvalue’ => ’1′
there is also a separate Zend Methods to be used like so:

$disclaimer>setCheckedValue(''); $disclaimer&t;setUnchedkValue('');

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!