when i debug($this->request->data) i dont get the radio button value , this is my form ( CakePHP 2 ) :
echo $this->Form->input('Gender', array(
'type' => 'radio',
'legend' => false,
'separator' => '</li><li>',
'value' => empty($paramsFilter['gender']) ? '' : $paramsFilter['gender'],
'div' => false, 'label' => true,
'options' => array(1 => "female", 2 => "Male"),
'default' => '1',
'hiddenField' => false
Are you sure this input is within the form element?
Also, the value with the if condition makes me nervous… I do recommend setting it as a variable somewhere else, ideally the controller. The more logic you have in your views, the higher the chance to make errors.
Have you made sure that the value field is actually being filled with the desired content in the html?
Other than that, I always recommend to just look at the html; Ultimately, Cakephp only creates regular form elements, there’s no magic going on, so you can just look at it and see where the error is. Maybe also run your html through a validator.
Yes Ali ,im sure, it works with select box and other inputs, but not with radio button
I tried using precisely the same code in my app, and it shows the value in the request data without any problems, so it most likely isn’t an error in the input code itself.
However, a value will only be returned if a radio box is actually selected. If both radio boxes are left unchecked, no value will be returned, naturally.
If $paramsFilter[‘gender’] is empty, none of the radio boxes will be checked, thus the value won’t show up (even if a default value is set).
Have you tried setting a specific value like ‘1’?
If it won’t work even then, the error might be somewhere else entirely. However, I suspect that it has to do with the conditional value…