Checkbox values not storing using PHP API [RESOLVED]

I’m trying to submit a form through a custom front end, using AJAX and the GFAPI::add_entry function. I have data submitting but can’t seem to get checkboxes to store. There’s been a few topics I’ve found (here for eg) that reference using a different ID (i.e. ID_index) but I just can’t seem to get it right.

The code I’m running is GFAPI::add_entry($formEntry);, where a var_dump of $formEntry just before submission gives the below.

array(5) {
    ["form_id"]=> int(30)
    [59]=> string(0) ""
    [1]=> string(3) "USA"
    [5]=> string(2) "UK"
    [12]=> array(1) {
        [0]=> string(6) "Canada"
    }
}

Fields 1 and 5 store as expected, but field 12 just won’t go in (that’s the checkbox list). Here’s a shot of the admin setup for reference.

I’ve tried having the object reference input_12_1, 12_1 and various other combinations - any support would be greatly appreciated.

Thanks

You would include each checkbox choice that is selected in the array using its input number as the key e.g.

'5' => 'UK',
'12.3' => 'Canada',
1 Like

Absolute legend, thanks for this Richard! Not sure if I just missed it in the documentation, but adding it into this section would be really useful - https://docs.gravityforms.com/entry-object/#h-entry-json

Something like:

{
    "1": "Third Choice",
    "2": "This is text content",
    "3.1": "This is a checkbox content",
    "3.2": "This is another checkbox content",
    "id": "1",
    "form_id": "1",
    ...
}
1 Like