public function CampaignMonitorIcsForm::submitForm in Campaign Monitor 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- modules/
campaignmonitor_ics/ src/ Form/ CampaignMonitorIcsForm.php, line 306
Class
- CampaignMonitorIcsForm
- Subscribe to a campaignmonitor list.
Namespace
Drupal\campaignmonitor_ics\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$lists = campaignmonitor_get_lists();
$values = $form_state
->getValues();
$config = $form_state
->getValue('config');
$config = unserialize($config);
switch ($config['list']) {
case 'single':
$selection = [
$form_state
->getValue('list_id'),
];
break;
default:
$selection = $form_state
->getValue('selection');
}
$CustomFields = isset($values['CustomFields']) ? $values['CustomFields'] : NULL;
$name = isset($values['name']) ? SafeMarkup::checkPlain($values['name'])
->__toString() : NULL;
$email = SafeMarkup::checkPlain($values['email'])
->__toString();
foreach ($selection as $list_id) {
if ($list_id === 0) {
continue;
}
if (campaignmonitor_subscribe($list_id, $email, $name, $CustomFields)) {
drupal_set_message(t('You are subscribed to the @name list.', [
'@name' => $lists[$list_id]['name'],
]));
}
else {
drupal_set_message(t('You were not subscribed to the list, please try again.'));
}
}
}