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

Friday, 16th July 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!

Share this on:

Download PDFDownload PDF

Tags:

2 Responses to “Create a license agreement accept form checkout field within a Subform with Zend Framework”

  1. admin says:
    Epiphany 2.29.92 Epiphany 2.29.92 Debian GNU/Linux x64 Debian GNU/Linux x64
    Mozilla/5.0 (X11; U; Linux x86_64; en-us) AppleWebKit/531.2+ (KHTML, like Gecko) Safari/531.2+ Debian/squeeze/sid () Epiphany/2.29.92

    That’s rather strange but today the same Checkbox was not working, however I did minor modifications to the Checkbox Zend code forelisted and now it works fine, here is the new working code:

    $accept_disclaimer = new Zend_Form_SubForm();
    $accept_disclaimer->addElements(array(

    $disclaimer = new Zend_Form_Element_Checkbox(‘accept_disclaimer’, array(
    ‘required’ => true,
    ‘label’ => “risk statement”,
    ‘description’ => “your description”,
    ‘uncheckedvalue’ => ”,
    ‘checkedvalue’ => ‘0’,
    ‘value’ => 1,
    // ‘checked’ => 1,
    // ‘unchecked’ => ”,

    )),
    ));

    Cheers 🙂

    View CommentView Comment
  2. Waneta Westermark says:
    Opera 9.64 Opera 9.64 Windows XP Windows XP
    Opera/9.64(Windows NT 5.1; U; en) Presto/2.1.1

    I have been just analyzing this post it’s very well crafted, I’m searching on the web looking for the best way to start this weblog thing and your site happens to be quite professional.

    View CommentView Comment

Leave a Reply

CommentLuv badge