Question

I am trying to process data to a field with the API reference 'custom11746175'. However, this field has checkboxes and I want to process multiple values when necessary. Right now, I only have this, which will only process one of the values "Off-g", "On-g", "On-h" or "On-i" (the last defined one):

if (($_POST['custom13346240'] == 'Off-g')) {
$contactData['custom11746175'] = "Off-g";
}
if (($_POST['custom13346240'] != 'Off-g')) {
$contactData['custom11746175'] = "On-g";
}
if ($_POST['custom13500281']) {
$contactData['custom11746175'] = "On-h";
}           
if ($_POST['custom11746175'] == 'Yes') {
$contactData['custom11746175'] = "On-i";
}

What do I need to change in case I want to process all of the defined values (the number can vary) and have them marked in the checkboxes? Should I construct an array, to obtain something like a multidimensional field?

Was it helpful?

Solution

Yeah an array is what you need, if you put the double brackets [ ] after the $contactData['custom11746175'] varaible is will add the new item to an array in $contactData['custom11746175'] like this...

if (($_POST['custom13346240'] == 'Off-g')) {
    $contactData['custom11746175'][] = "Off-g";
}
if (($_POST['custom13346240'] != 'Off-g')) {
    $contactData['custom11746175'][] = "On-g";
}
if ($_POST['custom13500281']) {
    $contactData['custom11746175'][] = "On-h";
}           
if ($_POST['custom11746175'] == 'Yes') {
    $contactData['custom11746175'][] = "On-i";
}

Then to get the first element in the array you could simply do $contactData['custom11746175'][0]

OTHER TIPS

The team from Solve360 pointed out that the fields allow comma-separated values for multiple checkboxes. Therefore I changed the code above to this:

$items = "";

if (($_POST['custom13346240'] == 'Off-g')) {
    $items = $items . ',' . "Off-g";
}
if (($_POST['custom13346240'] != 'Off-g')) {
    $items = $items . ',' . "On-g";
}
if ($_POST['custom13500281']) {
    $items = $items . ',' . "On-h";
}            
if ($_POST['custom11746175'] == 'Yes') {
    $items = $items . ',' . "On-i";
}

$contactData['custom11746175'] = $items;

Hope that will help someone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top