function _mailchimp_insert_drupal_form_tag in Mailchimp 6.2
Same name and namespace in other branches
- 7 mailchimp.module \_mailchimp_insert_drupal_form_tag()
Convert mailchimp form elements to Drupal Form API
Parameters
<type> $mergevar:
Return value
<type>
1 call to _mailchimp_insert_drupal_form_tag()
- _mailchimp_subscribe_anon_form in ./
mailchimp.module - Helper function to return form elements for a single anon newsletter
File
- ./
mailchimp.module, line 727 - Mailchimp module.
Code
function _mailchimp_insert_drupal_form_tag($mergevar) {
// Insert common FormAPI properties
$input = array(
'#title' => $mergevar['name'],
'#weight' => $mergevar['order'],
'#required' => $mergevar['req'],
'#default_value' => $mergevar['default'],
);
switch ($mergevar['field_type']) {
case 'dropdown':
// dropdown is mapped to <select> element in Drupal Form API
$input['#type'] = 'select';
// Creates options, we must delete array keys to have revealant information
// on MailChimp
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 revealant information
// on MailChimp
foreach ($mergevar['choices'] as $choice) {
$choices[$choice] = $choice;
}
$input['#options'] = $choices;
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;
}