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]
Comment | File | Size | Author |
---|---|---|---|
#1 | mailchimp_lists-add-support-for-html5-email-type-input-fields-1934544-1.patch | 943 bytes | TomPenzer |
mailchimp_lists-add-support-for-html5-email-type-input-fields.patch | 985 bytes | TomPenzer | |
Comments
Comment #0.0
TomPenzer CreditAttribution: TomPenzer commentedclarified last sentence
Comment #0.1
TomPenzer CreditAttribution: TomPenzer commentedAdded reference to 'Email' module in addition to 'Elements'
Comment #0.2
TomPenzer CreditAttribution: TomPenzer commentedRemoved reference to 'Email' module adding support for emailfield or an equivalent HTML5 email field. Turns out, it doesn't.
Comment #1
TomPenzer CreditAttribution: TomPenzer commentedHere's a slightly simpler version:
Comment #2
TomPenzer CreditAttribution: TomPenzer commentedAny 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.
Comment #3
TomPenzer CreditAttribution: TomPenzer commentedNote 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')){
Comment #4
gcbIncluded in latest release. Thanks @TomPenzer!
Comment #4.0
gcbAdd note about questionable Drupal 8 support