function mailchimp_insert_drupal_form_tag in Mailchimp 7.3
Same name and namespace in other branches
- 8 mailchimp.module \mailchimp_insert_drupal_form_tag()
- 7.5 mailchimp.module \mailchimp_insert_drupal_form_tag()
- 7.4 mailchimp.module \mailchimp_insert_drupal_form_tag()
- 2.x mailchimp.module \mailchimp_insert_drupal_form_tag()
Convert mailchimp form elements to Drupal Form API.
Parameters
array $mergevar: The mailchimp-formatted form element to convert.
Return value
array A properly formatted drupal form element.
1 call to mailchimp_insert_drupal_form_tag()
- mailchimp_signup_subscribe_form in modules/
mailchimp_signup/ mailchimp_signup.module - Returns a subscription form for mailchimp lists.
File
- ./
mailchimp.module, line 1280 - Mailchimp module.
Code
function mailchimp_insert_drupal_form_tag($mergevar) {
// Insert common FormAPI properties:
$input = array(
'#title' => t('@mergevar', array(
'@mergevar' => $mergevar['name'],
)),
'#weight' => $mergevar['order'],
'#required' => $mergevar['req'],
'#default_value' => $mergevar['default'],
);
switch ($mergevar['field_type']) {
case 'address':
// Sub-array of address elements according to MailChimp specs.
// https://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
$input['#type'] = 'container';
$input['#tree'] = TRUE;
$input['addr1'] = array(
'#title' => t('Address 1'),
'#type' => 'textfield',
);
$input['addr2'] = array(
'#title' => t('Address 2'),
'#type' => 'textfield',
);
$input['city'] = array(
'#title' => t('City'),
'#type' => 'textfield',
);
$input['state'] = array(
'#title' => t('State'),
'#type' => 'textfield',
'#size' => 2,
'#maxlength' => 2,
);
$input['zip'] = array(
'#title' => t('Zip'),
'#type' => 'textfield',
'#size' => 6,
'#maxlength' => 6,
);
$input['country'] = array(
'#title' => t('Country'),
'#type' => 'textfield',
'#size' => 2,
'#maxlength' => 2,
);
break;
case 'dropdown':
// Dropdown is mapped to <select> element in Drupal Form API.
$input['#type'] = 'select';
// Creates options, we must delete array keys to have relevant information
// on MailChimp.
$choices = array();
foreach ($mergevar['choices'] as $choice) {
$choices[$choice] = $choice;
}
$input['#options'] = $choices;
break;
case 'radio':
// Radio is mapped to <input type='radio' /> i.e. 'radios' element in
// Drupal Form API.
$input['#type'] = 'radios';
// Creates options, we must delete array keys to have relevant information
// on MailChimp.
$choices = array();
foreach ($mergevar['choices'] as $choice) {
$choices[$choice] = $choice;
}
$input['#options'] = $choices;
break;
case 'email':
if (element_info_property('emailfield', '#type')) {
// Set to an HTML5 email type if 'emailfield' is supported:
$input['#type'] = 'emailfield';
}
else {
// Set to standard text type if 'emailfield' isn't defined:
$input['#type'] = 'textfield';
}
$input['#size'] = $mergevar['size'];
break;
default:
// This is a standard input[type=text] or something we can't handle with
// Drupal FormAPI.
$input['#type'] = 'textfield';
$input['#size'] = $mergevar['size'];
break;
}
// Special cases for MailChimp hidden defined fields:
if ($mergevar['public'] == FALSE) {
$input['#type'] = 'hidden';
}
return $input;
}