How to get checkbox value in codeigniter?

Member

by aubrey , in category: PHP Frameworks , 2 months ago

How to get checkbox value in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , 2 months ago

@aubrey 

To get checkbox value in CodeIgniter, you can use the following steps:

  1. In your HTML form, create a checkbox element and assign it a name attribute:
1
<input type="checkbox" name="checkbox_name" value="1">


  1. In your controller method, you can retrieve the checkbox value using the input class provided by CodeIgniter:
1
$checkbox_value = $this->input->post('checkbox_name');


  1. You can now use the $checkbox_value variable to check if the checkbox is checked or not:
1
2
3
4
5
6
7
if($checkbox_value){
    // Checkbox is checked
    echo "Checkbox is checked";
} else {
    // Checkbox is not checked
    echo "Checkbox is not checked";
}


That's it! You have successfully retrieved the checkbox value in CodeIgniter.