PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 2, 2022

[FIXED] Getting always last value when trying to create a radio button using loop in cakephp

 February 02, 2022     cakephp, cakephp-4.x     No comments   

Issue

I'm trying to create a radio button using a loop

<?= $this->Form->create($account) ?>
<?php foreach($gametitles as $gametitle): ?>
        <?= $this->Form->radio(
                  'gametitle_id',
                         [
                           ['value' => $gametitle->id,'text'=>'','hiddenField' => false],
                         ]
             ); 
        ?>
<?php endforeach; ?>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>

I have added 'hiddenField' => false , but in DOM I'm seeing still hidden field displaying. In output I'm getting always empty value if I select without last radio button.

[
'gametitle_id' => '',
]

If I use name as an array gametitle_id[] I am getting an array

'gametitle_id' => [
(int) 0 => '',
(int) 1 => '',
(int) 2 => '4',
(int) 3 => '',
(int) 4 => '',
],

How I will get only one value that has selected in radio button ? I have used 'hiddenField' => false, still why hidden field is displaying ?


Solution

You have set 'hiddenField' => false in options ! You have to set it with name.

echo $this->Form->radio(
    'favorite_color',
    [
        ['value' => 'r', 'text' => 'Red', 'style' => 'color:red;']
    ],
    ['hiddenField' => false]
)


Answered By - Alimon Karim
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing