Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,

I am working in codeigniter 4, I want to submit array checkboxes in which some may be checked and some may be unchecked, so I want to insert 1 and 0 into table accordingly.

My View like this:

PHP
<td class="text-center"><input type="checkbox" name="add[]"  class="form-check"></td>
<td class="text-center"><input type="checkbox" name="view[]" class="form-check"></td>
<td class="text-center"><input type="checkbox" name="update[]"  class="form-check"></td>
<td class="text-center"><input type="checkbox" name="delete[]"  class="form-check"></td>



I receive values of only checked checkboxes and not the whole array, what to do please help.

What I have tried:

PHP
$add = $this->request->getVar('add');
        $view = $this->request->getVar('view');
        $update = $this->request->getVar('update');
        $delete = $this->request->getVar('delete');
Posted
Comments
Richard Deeming 29-Nov-22 9:24am    
That's how HTML checkboxes work; only the value of the checked items is sent to the server. You're going to need to change your approach; unfortunately, you haven't explained what you're trying to do in enough detail to suggest how to do that.
nyt1972 29-Nov-22 9:38am    
Thanks, my html is a page to grant permissions to classes, that is add/view/delete etc, so some classes may have add and some may have view and some have none, so I want to insert accordingly. Is it enough explanation?
Richard Deeming 29-Nov-22 10:06am    
So your rows have some sort of ID or key to identify them?

And what are you currently doing with the arrays?
nyt1972 29-Nov-22 10:12am    
I have table with following kind of values and I want to update Add, View or Delete with 1 or 0
ID Class Add View Update Delete
1 Class1  1
2 Class2       1
3 Class3             1
4 Class4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900