| Project: | MailChimp |
| Version: | 7.x-2.x-dev |
| Component: | Lists |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Made a patch to Mailchimp_Lists module to add support for HTML5 [type="email"] input fields on Mailchimp list forms if 'emailfield' is a defined field type (i.e. when the 'Elements' module is enabled in Drupal 7). This patch adds a handler for 'email' field_type to the mailchimp_lists_insert_drupal_form_tag function which sets the input type to 'emailfield' when it's a defined element type, or to the default 'textfield' otherwise.
Here's the code added to the function, on line 836 of mailchimp/modules/mailchimp_lists/mailchimp_lists.module:
case 'email':
$emailfield_info = element_info('emailfield');
if (isset($emailfield_info['#type'])){
// Set to an HTML5 email type input[type=email] if 'emailfield' is supported
$input['#type'] = 'emailfield';
} else {
// Set to standard text type input[type=text] if 'emailfield' isn't defined
$input['#type'] = 'textfield';
};
$input['#size'] = $mergevar['size'];
break;Seems like a relatively safe way to add support for HTML5 email fields in Drupal 7, and my understanding is that since 'emailfield' is a standard input type in Drupal 8, this patch should still work as intended with D8 as well, no longer requiring the addition of a module such as 'Elements'.
[Edit]Turns out, the field in Drupal 8 will be named 'email', not 'emailfield', so some additional code will likely be needed for Drupal 8 support. [/Edit]
| Attachment | Size |
|---|---|
| mailchimp_lists-add-support-for-html5-email-type-input-fields.patch | 985 bytes |
Comments
#1
Here's a slightly simpler version:
case 'email':if (element_info_property('emailfield', '#type')){
// Set to an HTML5 email type input[type=email] if 'emailfield' is supported
$input['#type'] = 'emailfield';
} else {
// Set to standard text type input[type=text] if 'emailfield' isn't defined
$input['#type'] = 'textfield';
};
$input['#size'] = $mergevar['size'];
break;
#2
Any interest in this feature? This is needed in order for mobile devices (iOS and Android) to display the special 'email address' keyboard with convenient 'underscore' and 'at' symbol placement.
#3
Note that the Webform project had an interesting solution to this without depending on the 'Elements' module, and theirs is backwards-compatible with Drupal 6.
Otherwise, for Drupal 6, you could do:
if (module_exists('elements')){