Send 0 for value for checkbox being unchecked - CodeIgniter |
I Want send send 0 if check box is not check so how i can do it, I tried in hidden variable its working, But checkbox is in loop so i did not get proper output.So How How to implement it Please help me. here i put my view code
Here Is My View: <form method="POST" action="<?php echo base_url() . "welcome/user_manager/" ?>"> <label>Select User</label> <select name="user_role" id="user_role" onchange="calculate(this)"> <option>--Select User--</option> <?php foreach ($roll_get as $roll) { ?> <option value="<?php echo $roll->user_id; ?>" id="<?php echo $roll->user_id; ?>"><?php echo $roll->full_name; ?></option> <?php } ?> </select><br> <input id="checkAll" type="button" value="Check All"> <div class="button"> <?php foreach ($listMenuLevel1 as $menu1) { ?> <div id="checkboxlist"> <li class="treeview"> <input type="checkbox" name="sample[]" value="1"/> <span><?php echo $menu1->category_name; ?></span> </a> <?php if (count($this->main_model->listchildMenus($menu1->category_id)) > 0) { ?> <ul class="treeview-menu"> <?php foreach ($this->main_model->listchildMenus($menu1->category_id) as $menu2) { ?> <li ><input type="checkbox" name="sample[]" value="1" /><a href="<?php echo base_url(); ?><?php echo $menu2->category_link; ?>"><?php echo $menu2->category_name; ?></a></li> <ul> <?php foreach ($this->main_model->listchildMenus($menu2->category_id) as $menu3) { ?> <li><input type="checkbox" name="sample[]"value="1"/><a href="<?php echo base_url(); ?><?php echo $menu3->category_link; ?>"><?php echo $menu3->category_name; ?></a></li> <?php } ?> </ul> <?php } ?> </ul> <?php } ?> </li> </div> <?php } ?> <input type="submit" class="btn btn-primary" value="Save"> </form>
@jaydevvara
I don't know if I understand your question. Do you need to know if the value is zero before you create the menu?
(07-20-2018, 05:17 AM)php_rocs Wrote: @jaydevvara nono, 1st time value will null, after click on submit i want the value 0 or 1, if checked then 1 either 0, i hope you understand my question
If he is read the values from the database then he will need to add a field to hold the checkbox value
to the table, this way he can do a foreach check on the values and assign a 0 or 1 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Heres what I use, if you still need it, in yor controller write
$input['special'] = $this->input->post('special') ?? 0; works with PHP >= 7
|
Welcome Guest, Not a member yet? Register Sign In |