Welcome Guest, Not a member yet? Register   Sign In
retain state with radio buttons and checkboxes
#1

I looked everywhere in the forums and can't find an answer to how I would retain the value of a radio button, or a checkbox using set_radio() or set_checkbox() after a form is submitted. I also tried all sorts of ways of inserting set_radio() and set_checkbox(). What syntax should I use in the code below?

Example:
PHP Code:
<div class="form-control">
 
    Client has read and understood the confidentiality guidelines.
 <?
php 
    $data 
= array(
 
'name'  => 'guidelines',
 
'id' => 'signed_yes',
 
'value' => 'yes',
 
'style' => 'margin-left: 20px;'
 
);
 
   echo form_radio($data); 
 
?>
 <?php echo form_label('Yes''signed_yes'); ?>
 <?php 
 $data 
= array(
 
'name'  => 'guidelines',
 
'id' => 'signed_no',
 
'value' => 'no',
 
'checked' => TRUE  // default value
 
'style' => 'margin-left: 20px;'
 
);
 echo 
form_radio($data); 
 
?>
 <?php echo form_label('No''signed_no'); ?>
 </div><!-- end of .form-control -->
        <div class="form-control">
 A signed confidentiality guideline is on file for this client.
 <?php 
 $data 
= array(
 
'name'  => 'guidelines_signed',
 
'value' => 'yes',
 
'style' => 'margin-left: 20px;'
 
);
 echo 
form_checkbox($data)); 
 
?>
 </div><!-- end of .form-control --> 
Reply
#2

Maybe this will help you out:

CodeIgniter Checkboxes
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

I checked that out and the tutorial doesn't use form-helper functions. My problem is how to integrate set_checkbox() and set_radio into the code that I have posted here, not into the normal php way of coding form controls.
Reply
#4

(This post was last modified: 11-21-2015, 07:42 PM by orionstar.)

(11-21-2015, 10:41 AM)webmachine Wrote: I looked everywhere in the forums and can't find an answer to how I would retain the value of a radio button, or a checkbox using set_radio() or set_checkbox() after a form is submitted. I also tried all sorts of ways of inserting set_radio() and set_checkbox(). What syntax should I use in the code below?

Example:
PHP Code:
<div class="form-control">
 
    Client has read and understood the confidentiality guidelines.
 <?
php 
    $data 
= array(
 
'name'  => 'guidelines',
 
'id' => 'signed_yes',
 
'value' => 'yes',
 
'style' => 'margin-left: 20px;'
 
);
 
   echo form_radio($data); 
 
?>
 <?php echo form_label('Yes''signed_yes'); ?>
 <?php 
 $data 
= array(
 
'name'  => 'guidelines',
 
'id' => 'signed_no',
 
'value' => 'no',
 
'checked' => TRUE  // default value
 
'style' => 'margin-left: 20px;'
 
);
 echo 
form_radio($data); 
 
?>
 <?php echo form_label('No''signed_no'); ?>
 </div><!-- end of .form-control -->
        <div class="form-control">
 A signed confidentiality guideline is on file for this client.
 <?php 
 $data 
= array(
 
'name'  => 'guidelines_signed',
 
'value' => 'yes',
 
'style' => 'margin-left: 20px;'
 
);
 echo 
form_checkbox($data)); 
 
?>
 </div><!-- end of .form-control --> 

PHP Code:
$data = array(
 
'name'  => 'guidelines_signed',
 
'value' => set_checkbox('guidelines_signed''yes'),
 
'style' => 'margin-left: 20px;'
 
);
 echo 
form_checkbox($data)); 
If you have multiple checkbox with the same name you should put [] to the end of the field end (e.g. guidelines_signed[]) and use like that  everywhere (valudation rules, form_, etc...).
Reply
#5

Thanks, I'll try that out. Does the same thing work for the radio buttons?
Reply
#6

(11-21-2015, 07:42 PM)webmachine Wrote: Thanks, I'll try that out. Does the same thing work for the radio buttons?

Quote: This function is identical to the [font=Consolas, 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier, monospace]set_checkbox() function above.[/font]
http://www.codeigniter.com/user_guide/he...elper.html

It should...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB