Welcome Guest, Not a member yet? Register   Sign In
set_radio problem
#2

[eluser]TheFuzzy0ne[/eluser]
I'm not entirely sure how you're supposed to do it when you're using an array to pass the parameters to the form_radio() function, but the code below might work.

Code:
<?php # test set_radio

echo '<div class="error">'.validation_errors().'</div>';

echo '<p>Received '.$result.' as value for $result</p>';

echo form_open('/start/setval/');      

echo '<p>';
    $attrs = array('name' => 'result', 'id' => 'id_resultval_1', 'value'=> '1', 'checked' => (set_radio('result', '1') != ''), 'class' => 'inputRadio');
    echo form_radio($attrs);
    echo form_label('Result 1', 'id_resultval_1');
echo '</p>';
            
echo '<p>';
    $attrs = array('name' => 'result', 'id' => 'id_resultval_11', 'value'=> '11', 'checked' => (set_radio('result', '11') != ''), 'class' => 'inputRadio');
    echo form_radio($attrs);
    echo form_label('Result 11', 'id_resultval_11');
echo '</p>';
?&gt;

<div class="submit">
&lt;input name="submit" class="inputButton" type="submit" id="btnCancel" value="Go" /&gt;
&lt;input name="submit" class="inputButton" type="submit" id="btnSave" value="Cancel" /&gt;
</div>

&lt;?php
echo form_close();
?&gt;

form_radio() expected the array to contain an index called "checked" and for the value to be either TRUE or FALSE. You weren't passing it at all in your array, and in any case, set_radio() returns either an empty string, or ' checked="checked"', not a boolean as you might expect.

set_radio() also takes an optional third parameter, which is used as the default. It's up to you to come up with the condition that returns TRUE or FALSE according to your defaults.

Hope this helps.


Messages In This Thread
set_radio problem - by El Forum - 03-11-2013, 07:13 AM
set_radio problem - by El Forum - 03-11-2013, 08:13 AM
set_radio problem - by El Forum - 03-11-2013, 08:31 AM
set_radio problem - by El Forum - 03-12-2013, 01:45 AM
set_radio problem - by El Forum - 03-12-2013, 11:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB