0

I am sure this is straightforward but I need to grab whatever is selected in my checkboxes and enter all values, as text, into my text field. I am using Laravel.

Can anyone point me in the right direction please?

VIEW

<input type="checkbox" value="Item 1" name="other_info[]">
<input type="checkbox" value="Item 2" name="other_info[]">
<input type="checkbox" value="Item 3" name="other_info[]">

CONTROLLER

$user = new User;
$user->firstname = Input::get('firstname');
$user->other_info = Input::get('other_info');
$user->save();
1
  • 1
    You should add some debugging in your controller to see what you're getting. Like dd(Input::all()). I think you'll see that Input::get('other_info') is an array, which means you probably want to implode() or json_encode() it before sticking it in the DB. Commented Nov 25, 2014 at 22:04

1 Answer 1

1

I'm gonna assume that you want to store them in the database. My question is then "why store it as text?".

If you load the options you are presenting the user with from your db, then you can reference those fields in the db by their id's. This will improve loading time and reduce the size of your db.

Instead of getting the full names and storing those, just make a simple form macro to build the inputs with the values from the db, make sure it will pass as an array. Then Input::get the values and attach them through a pivot table, thus referencing the original option.

Also, if you ever delete an option then it will also be detached from all userprofiles. If you don't want them detached from the userprofiles but also don't want them to show up in the options, then look into soft deleting.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your input. I appreciate this isn't ideal and farther down the project I will look at this. This field was originally a radio button, and has had to change to checkboxes just recently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.