Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP disable some radio buttons?

Tags:

php

cakephp

I have a simple form with some radio buttons. I want to disable some of the radio buttons, is this possible?

$sixMonths = true;
$twelveMonths = true;
$twentyfourMonths = false;

echo $this->McForm->create('Wizard',  array ('url'=>'/wizard/create'));

$options = array('24' => '24 months','12' => '12 months', '6' => '6 months');
$attributes = array('legend' =>false, 'default' => '6');
echo $this->McForm->radio('period', $options, $attributes);

echo $this->McForm->submit('Save');
echo $this->McForm->end();

So in this case I'd like to disable the first radio button and enable the other two.

I know I could probably do it with jQuery, but I'd prefer to do it without using it, is it possible? Any ideas?

Thanks!

like image 724
Eric Avatar asked Jun 28 '11 05:06

Eric


1 Answers

You can add a disabled array in $attributes that contains the values ​​of the radios:

$attributes = [
    'legend' => false, 
    'default' => '6', 
    'disabled' => ['6', '24']
];
like image 173
Paulo Mateus Avatar answered Sep 20 '22 12:09

Paulo Mateus