• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send 0 for value for checkbox being unchecked - CodeIgniter

#1
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>
Reply

#2
@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?
Reply

#3
(07-20-2018, 05:17 AM)php_rocs Wrote: @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?

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
Reply

#4
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 )
Reply

#5
(07-20-2018, 08:41 AM)InsiteFX Wrote: 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

Can you give me 1 example?
how to implement it
Reply

#6
Heres what I use, if you still need it, in yor controller write
$input['special'] = $this->input->post('special') ?? 0;
works with PHP >= 7
Reply

#7
(07-20-2018, 11:36 PM)Leo Wrote: Heres what I use, if you still need it, in yor controller write
$input['special'] = $this->input->post('special') ?? 0;
works with PHP >= 7


It Still not working...
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.