CodeIgniter Forums
set_radio() is inconvenient. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: set_radio() is inconvenient. (/showthread.php?tid=40068)



set_radio() is inconvenient. - El Forum - 03-29-2011

[eluser]cleansugar[/eluser]
if I use 'echo form_radio($s);' in view.

set_radio() is useless.

Code:
<?php foreach($question as $row):?>
        <?php $i++;?>
        <tr>
        <td>&lt;?=$row?&gt;</td>
        <td>&lt;? $s = array(
        'name' => 'q'.$i,
        'value' => set_radio('q'.$i, '1')
        );
        ?&gt;
        </td>
        <td>&lt;? $s = array(
        'name' => 'q'.$i,
        'value' => set_radio('q'.$i, '2')
        );

It returns:
<td>&lt;input type="radio" name="q1" value="" /&gt; </td>

because set_raidio is text:'checked='checked'.

so to Insert 'checked='checked' into form_radio() is impossible.

How can I insert submitted radio value into form_radio()?

Please, change API.


set_radio() is inconvenient. - El Forum - 03-29-2011

[eluser]fesweb[/eluser]
set_radio is not intended to return the value of the radio button, it is intended to return the radio button's state.

Try it like this instead, using a boolean test as the third parameter:
Code:
$radio_state = set_radio('my_field', 'car', $my_field == 'car');
$data = array(
    'name'        => 'my_field',
    'value'       => 'car',
    'checked'     => $radio_state
    );
echo form_radio($data);

Without the form_radio function it would look like this:
Code:
&lt;input type="radio" name="my_field" value="house"&lt;?php echo set_radio('my_field', 'house', $my_field == 'house'); ?&gt;&gt;
&lt;input type="radio" name="my_field" value="car"&lt;?php echo set_radio('my_field', 'car', $my_field == 'car'); ?&gt;&gt;



set_radio() is inconvenient. - El Forum - 10-26-2012

[eluser]Unknown[/eluser]
How does this work? Where do you insert this code in the view?