public function createCustomField($name, $type = 'text', $options = array(), $listId = null)
{
// set list ID
$listId = empty($listId) ? $this->getListId() : $listId;
// check if the given type is allowed
if (!empty($type) && !in_array($type, array('string', 'int', 'text', 'number', 'country', 'multiSelectOne', 'multiSelectMany'))) {
// type is not allowed
throw new CampaignMonitorException('This type is not allowed. Must be text, number, multiSelectOne or multiSelectMany.');
}
// if type is empty, just set it to text
if (empty($type) || $type == 'string') {
$type = 'text';
}
// catch 'int' type
if ($type == 'int') {
$type = 'number';
}
// if type is a multiple select, $options is required
if (in_array($type, array('multiSelectOne', 'multiSelectMany')) && empty($options)) {
// no options set
throw new CampaignMonitorException('You need to provide an array with options for a multiSelect type.');
}
// set parameters
$parameters['FieldName'] = (string) $name;
$parameters['DataType'] = (string) ucfirst($type);
// options found
if (!empty($options)) {
// set options
$parameters['Options'] = (array) $options;
}
// try and create the record
return (bool) $this->doCall('lists/' . $listId . '/customfields', $parameters, 'POST');
}