I want to store all the selected check box values in single-column separately like
here is my code for that
<tr> <th scope="row"> <input class="form-control" type="text" placeholder="Posts" readonly> </th> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Add"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="View"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Edit"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Delete"> </td> </tr> <tr> <th scope="row"> <input class="form-control" type="text" placeholder="Comments" readonly> </th> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Add"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="View"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Edit"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Delete"> </td> </tr> <tr> <th scope="row"> <input class="form-control" type="text" placeholder="User" readonly> </th> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Add"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="View"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Edit"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="Delete"> </td> </tr>
And want to store individually with its supporting read-only text? how to do that ??? And when user checks the checkbox (selected) should be stored in the database?? how to write store function for it ???
Advertisement
Answer
If you want to store all checkbox values using the markup you showed, you won’t be able to know which permission belongs to which model.
If you have to use that exact name and can’t provide more then one key => value as post data (for some reason), you would have to add some more info to the value field.
Example:
<tr> <th scope="row"> <input class="form-control" type="text" placeholder="Comments" readonly> </th> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="comment_Add"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="comment_View"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="comment_Edit"> </td> <td class="examplelink"> <input type="checkbox" name="checkPermission[]" value="comment_Delete"> </td> </tr>
Then when retrieving the data in back-end you would have to explode each value using delimiter “_” to find model at index 0 and permission at index 1.
EDIT: Or you could build a JS object containing all the data and send it as JSON data.