CodeIgniter Forums
set_radio() pre-populate problems - 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() pre-populate problems (/showthread.php?tid=43706)



set_radio() pre-populate problems - El Forum - 07-20-2011

[eluser]Unknown[/eluser]
I am trying to set a radio button as selected from the database but it isn't working.

This is the code I am using:
Code:
<input type="radio" name="volunteer_applied_c" value="Yes" <?php echo set_radio('volunteer_applied_c', 'Yes', $application_data['volunteer_applied_c'] == 'Yes'); ?>>Yes

I have verified that $application_data['volunteer_applied_c'] does contain the value of "Yes". What am I missing?


set_radio() pre-populate problems - El Forum - 07-20-2011

[eluser]Armchair Samurai[/eluser]
My guess is you need to explicitly set the boolean.

Code:
<input type="radio" name="volunteer_applied_c" value="Yes" <?php echo set_radio('volunteer_applied_c', 'Yes', ($application_data['volunteer_applied_c'] == 'Yes') ? TRUE : FALSE); ?>>Yes



set_radio() pre-populate problems - El Forum - 07-21-2011

[eluser]Unknown[/eluser]
Hmm, no dice. It works for validation to pre-populate but it doesn't load the db value on the first load.

edit: i ended up using a solution like this from here:

Code:
<?php $options = array(
                  ''       => 'Select',
                  'Yes'  => 'Yes'
                );
        
    echo form_dropdown('volunteer_applied_c', $options, set_value('volunteer_applied_c', $application_data['volunteer_applied_c']));
    
     ?>

If validation rules are set for the field then it will update the value from the submission after being pre-populated by the database value, $application_data['volunteer_applied_c']