#1 October 2, 2014 3:01pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Processing a List of Checkboxes

I'm having a little trouble creating a custom form field type which will be a list of checkboxes that a user can select and then all the selected values are stored as a single comma delimited string. I'm drawing it the same way the list form field is drawn, except that I removed the select and option tags and replaced them with a checkbox input. This correctly draws what I want. The problem I'm having is that on the process, only the last checked value is being stored. I can't figure out why this is since all of the checkbox inputs have the same name and when I check a box the input does have the checked="checked" added to it. I have printed the $_POST variable right after I hit the submit button but it also only shows the last checked value. Is there a way to get all the checked values to appear similar to how a regular checkbox would behave?

Thanks

Offline

#2 October 2, 2014 3:06pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Processing a List of Checkboxes

When you're drawing the <input> elements make sure you set the name attribute with [] at the end. I.e.

<input type="checkbox" name="<?=$field["key"]?>[]" value="checkbox_value" />

Offline

#3 October 2, 2014 4:21pm

jmason03
Member
Registered: January 9, 2014
Posts: 123

Re: Processing a List of Checkboxes

That worked perfect!

Thank you!

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.