inavalid data type msg when inserting a variable into custom field

Participant

inavalid data type msg when inserting a variable into custom field

I am trying to insert a string through a variable into a custom field.

 

$contact->custom_fields = array(array('name' => 'CustomField1', 'value' => $_POST['type_of_book']));

Inserts fine.

 

The code below:

$foo=$_POST['type_of_book'];
$contact->custom_fields = array(array('name' => 'CustomField1', 'value' => $foo));

 

 

 

Results in the following error msg.

 

 

[error_key] => json.type.invalid
            [error_message] => #/custom_fields/0/value: Value is of a disallowed type. Allowed types are: Null, String.

 

I need the variable because the it will contain multiple values from an imploded checkbox array.

 

Please advise why this generates an error?

 

1 REPLY 1
Moderator

What is the value of $foo?  If it is a boolean (true/false), PHP will serialize that to a boolean JSON value which is not valid for that field.  You would need to pass in a string value for true/false if you wanted to store that in the custom field.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page