CodeIgniter Forums
Validation and Checkbox - 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: Validation and Checkbox (/showthread.php?tid=10156)



Validation and Checkbox - El Forum - 07-21-2008

[eluser]Yash[/eluser]
Hi,

I need to store some initial value in checkbox. And I need to validate all fields.I'm using a hidden variable so that if it is not set I'll store initial value.Then after form submission it should maintain values and submit form if no error found.
Code:
if(!isset($_POST['start']))
  {
      
if($generalsettings['ShowRecentComments']==1)
        $ShowRecentComments=$this->validation->set_checkbox('ShowRecentComments', '1');
    else
        $ShowRecentComments=$this->validation->set_checkbox('ShowRecentComments', '0');
}

<input type="checkbox" name="ShowRecentComments" id="ShowRecentComments" <?=$ShowRecentComments?>/>

but this code is not working.

I have set fields in controller.
Any idea?