Welcome Guest, Not a member yet? Register   Sign In
set_value for radio button
#1

[eluser]Wonder Woman[/eluser]
Hello,

I have my form validation set up so that when the form is submitted, the users answer is highlighted, however how do I amend this code to take the stored answer from the database so that the correct answer is highlighted when the page is refreshed?

Code:
echo form_radio('publish', 1, (set_value($publish) == 1)).' Yes';
echo form_radio('publish', 0, (set_value($publish) == 0)).' No';

Thanks!
#2

[eluser]gbar[/eluser]
Hello, I use this code to receive the value of a radiobutton from the database:

Code:
<?php
                                $disabled = array(
                                'name'        => 'status',
                                'id'          => 'disabled',
                                'value'       => '0',
                                'checked'     => $record->status == '0' ? 'checked' : ''
                                );
                                
                                $enabled = array(
                                'name'        => 'status',
                                'id'          => 'enabled',
                                'value'       => '1',
                                'checked'     => $record->status == '1' ? 'checked' : ''
                                );                        
                            ?>
                        
                            <?php echo label('Disabled', 'disabled'); ?>
                            <?php echo form_radio($disabled); ?>
                            <?php echo label('Enabled', 'enabled'); ?>
                            <?php echo form_radio($enabled); ?>

I hope you help!




Theme © iAndrew 2016 - Forum software by © MyBB