CakePHP : Form Radio Default Checked Value

Thu, Apr 17, 2008

CakePHP, PHP

With the CakePHP FormHelper, you can output a set or a list of radio button widgets.

Usage

<?= $form -> radio($field, $options, $attributes); ?>

Example

<?= $form -> radio(‘Model.field’, array(‘Option1′, ‘Option2′, ‘Option3′), array(‘default’ => ‘option2′)); ?>

In the line of code above, you’ll notice the default attribute value. This specifies the value of the radio button which will be checked by default in case there is currently no value passed through the model data.

, , , , ,
scriptlancebannerpng

This post was written by:

Antonie Potgieter - who has written 57 posts on Lost-In-Code.

I (Antonie Potgieter) am a software engineer/web developer located in South Africa. My full-time work is the management of Tribulant Software and the development of its software packages.

Contact the author

3 Comments For This Post

  1. Safi Says:

    it is not working

  2. jeffery Says:

    thankz very much…………

    i was having some trouble displaying the selected value for radio using cake methiod…this solved it…great tip………….
    sometimes we make a mess for even the tings that can be done easily…

  3. Gaurav Says:

    Thanks it worked, I was looking for an answer to this. :-)

Leave a Reply