How do I update a multi-options (select many) field using PHP wrapper?

I created a custom multi-option (select many) field called 'Subscribedto' where the user can select which newsletter he wants to receive: 'News & Updates' and/or 'News from Partners'. Now I would like to update this field using the PHP API wrapper but can't figure out how to do this.

From my database:
'News & Updates' can be either 0 or 1
'News from Partners' can be either 0 or 1

The following does not work:
$extras = array('Subscribedto'=>array("News & Updates"=>0,"News from Partners"=>1));

$cm_res = $cm->subscriberAddWithCustomFields($email,$name, $extras);

jamesd jamesd, 7 years ago

In your post you appear to be attempting to populate a multi-option-select-many field with the personalization tag "Subscribedto". If so, and assuming that you have the options "News & Updates" and "News from Partners" defined for that field, you probably just want to populate $extras like so:

$extras = array('Subscribedto' => array("News & Updates", "News from Partners"));

Also, please note that there is a comment above the subscriberAddWithCustomFields code, which clearly explains how multi-option fields should be populated:

* @param mixed $fields Should be a $key => $value mapping. If there are more than one items for $key, let
*        $value be a list of scalar values. Example: array( 'Interests' => array( 'xbox', 'wii' ) )
bc173, 7 years ago

Thx James, but I'm still confused, with the code you suggest:

$extras = array('Subscribedto' => array("News & Updates", "News from Partners"));

I can't enabled/disable (or set true/false or on/off) to "News & Updates" and "News from Partners".

bc173, 7 years ago

Or in other words, when I want to uncheck all options, do I use the following?

$extras = array('Subscribedto' => array('',''));
bc173, 6 years ago

Ok, I figured it out myself after testing (thanks for the non-help CampaignMonitor).

Apparently to check an option, it is as simple as adding it to the array. Unchecking an option means leaving it out of the array.

Both options checked:

$extras = array('Subscribedto' => array("News & Updates", "News from Partners"));

Only the first option checked, the other ones are automatically unchecked:

$extras = array('Subscribedto' => array("News & Updates"));

The weird thing is, unchecking all options can only be achieved by placing rubbish in the array. I decided to use 'NULL' but it works with any value that is not matched with one of the options. Leaving the array empty: array() or adding an empty value to the array array('') would be more straight forward but doesn't do anything.

To uncheck all options:

$extras = array('Subscribedto' => array('NULL'));

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free