Storing Multople Checkbox Values in Database |
[eluser]xitclub[/eluser]
Hi all, This is my first post in community. The problem is i wanted to store multiple checkbox values in database but its storing only first value in database. my code is Form Code: <div class="row ex-row"> Model Code Code: public function UpdateExpertise($id) {
[eluser]InsiteFX[/eluser]
you need to check each checkbox, If the checkbox is not checked then it will not return it's emtpy. If no checkboxes are checked, the checkbox will not be set, so use the “empty” function to check for this case. so check to see if it is checked use isset() if not you need to assign a value to it. Code: // Just ruff code you can modify it. This is for an array of checkboxes.
[eluser]Tim Brownlaw[/eluser]
Just some ideas for you... In your Model you can replace this section Code: foreach($expertise as $value) { This has the small issue of appending a comma at the end of the string... which makes exploding it a lil tricky... There are of course ways around that but you might be better off using the php implode and explode functions ( read up on that in php.net) with something like... Code: // You will want to check that $expertise is an Array with values So you could do a callback on the form validation for 'expertise' to ensure that at least one entry has been checked before getting to the model call... ie check that it's an array and that it's count($expertise) > 0 Read the user guide on form validation callbacks... As always, it's a good thing to do a var_dump($_POST) or you can use the built in CI $this->input->post()by way of var_dump($this->input->post()); Same difference! I'd also recommend a read of https://ellislab.com/codeigniter/user-gu...input.html AND https://ellislab.com/codeigniter/user-gu...ation.html The user guide is your friend! Cheers
[eluser]xitclub[/eluser]
Hi, Thanks guys for solutions, this solved my problem
|
Welcome Guest, Not a member yet? Register Sign In |