Welcome Guest, Not a member yet? Register   Sign In
set_radio() is inconvenient.
#1

[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.
#2

[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;
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB