• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
set_radio() pre-populate problems

#1
[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?

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

#3
[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']


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.