Cakephp 3.7 : Assign custom value to radio button

#1

Hello All,

I am facing a problem in assigning value to radio button in cakephp 3.7. Any help will be highly appreciated. Its urgent, please help me as soon as possible. please add your answer to below :-1:

<?php echo $this->Form->radio('entry_level',[' '], array('label'=>'', 'id'=>'radio-1' ,'class'=>'option-input radio','type'=>'radio','value'=>'1','hiddenField'=>false)); ?>

value still taking 0 but it should be 1.

Please help, your reply will be highly appreciated.

Thanks

0 Likes

#2

Radio buttons can have multiple values, not just one. The second parameter (which you have as just [' '], equivalent to [0 => ' '] and hence the value of 0 you’re seeing) is where you provide the list of values and their associated labels. Like [1 => ''] if you really do want no text associated with the button.

Also, you don’t need 'type' => 'radio' when you’re using the radio function.

https://book.cakephp.org/3.0/en/views/helpers/form.html#creating-radio-buttons

0 Likes