CodeIgniter Forums
[SOLVED] how Re-populating the check box value in form? - 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: [SOLVED] how Re-populating the check box value in form? (/showthread.php?tid=30969)



[SOLVED] how Re-populating the check box value in form? - El Forum - 06-01-2010

[eluser]suba[/eluser]
Hi

In my form , I have one group of check box, text box, drop down list.

When I click submit button , I want to re-populate value in my selected check box.

how is it?

Text box & drop down list has worked properly.

Example:
Code:
<?
$att=array('name'=>'name','value'=>set_value('name'))
echo form_input($att);
?>
but in check box , I don't know how to re-populate the selected check box which is checked.

Thanks


[SOLVED] how Re-populating the check box value in form? - El Forum - 06-01-2010

[eluser]Alex-Tunbridge[/eluser]
Well check box's return TRUE or FALSE correct?

Well so in your view just do something like.

<input type="checkbox" name="name"<?=($checked ? ' CHECKED' : '')?>/>


[SOLVED] how Re-populating the check box value in form? - El Forum - 06-01-2010

[eluser]suba[/eluser]
hi all

This is my form with re-populate check box value after submit . I solved my problem myself. This is my actual code. If you need, pls refer this for your future.

Code:
<?
$check=array('English'=>array('name'=>'language[]','id'=>'english','value'=>'ENGLISH'),'Chinese'=>array('name'=>'language[]','id'=>'chinese','value'=>'CHINESE'),'Malay'=>array('name'=>'language[]','id'=>'malay','value'=>'MALAY'),'Tamil'=>array('name'=>'language[]','id'=>'tamil','value'=>'TAMIL'),'Hokkien'=>array('name'=>'language[]','id'=>'hokkien','value'=>'HOKKIEN'),'Cantonese'=>array('name'=>'language[]','id'=>'cantonese','value'=>'CANTONESE'),'Teochew'=>array('name'=>'language[]','id'=>'teochew','value'=>'TEOCHEW'));

// problem solved here. this code for re-populate check box value
$lang=$this->input->post('language');
for($i=0;$i<count($lang);$i++)
$languge[$lang[$i]]=$lang[$i];
foreach($check as $key=>$value){
if( isset($languge[$value['value']]))
$value['checked']=true;                            
echo form_checkbox($value).$key;
$i++;
}
unset($lang);unset($language)
?&gt;

Thanks..


[SOLVED] how Re-populating the check box value in form? - El Forum - 08-14-2011

[eluser]sineld[/eluser]
this is my way to this:
Code:
&lt;?=form_checkbox(array('name' => 'uyeBilgi', 'value' => 1, 'checked' => (isset($_POST['uyeBilgi']) || !$_POST) ? true : false, 'id'=> 'uyeBilgi'))?&gt;

topic is may be old but I thought somebody may need it.