# Can't get radio button value in my controller

**URL:** <https://discourse.cakephp.org/t/cant-get-radio-button-value-in-my-controller/547>\
**Category:** Need Help\
**Created:** [June 15, 2016, 10:34am UTC](https://discourse.cakephp.org/t/cant-get-radio-button-value-in-my-controller/547 "2016-06-15T10:34:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferrra](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@ferrra](https://discourse.cakephp.org/u/ferrra)\
**Post date:** [June 15, 2016, 10:34am UTC](https://discourse.cakephp.org/t/cant-get-radio-button-value-in-my-controller/547/1 "2016-06-15T10:34:30Z")

</div>

Hi,  
when i debug($this-\>request-\>data) i dont get the radio button value , this is my form ( CakePHP 2 ) :

```
                            <?php
                            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
                            ));
```

---

<div class="post-metadata">

**Author:** ![ali](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ali/32/123_2.png) [@ali](https://discourse.cakephp.org/u/ali)\
**Post date:** [June 16, 2016, 12:13am UTC](https://discourse.cakephp.org/t/cant-get-radio-button-value-in-my-controller/547/2 "2016-06-16T00:13:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ferrra](https://avatars.discourse-cdn.com/v4/letter/f/edb3f5/32.png) [@ferrra](https://discourse.cakephp.org/u/ferrra)\
**Post date:** [June 16, 2016, 2:41pm UTC](https://discourse.cakephp.org/t/cant-get-radio-button-value-in-my-controller/547/3 "2016-06-16T14:41:35Z")

</div>

Yes Ali ,im sure, it works with select box and other inputs, but not with radio button

---

<div class="post-metadata">

**Author:** ![ali](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ali/32/123_2.png) [@ali](https://discourse.cakephp.org/u/ali)\
**Post date:** [June 18, 2016, 8:07pm UTC](https://discourse.cakephp.org/t/cant-get-radio-button-value-in-my-controller/547/4 "2016-06-18T20:07:08Z")

</div>

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…
