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]

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TomPenzer’s picture

Issue summary: View changes

clarified last sentence

TomPenzer’s picture

Issue summary: View changes

Added reference to 'Email' module in addition to 'Elements'

TomPenzer’s picture

Issue summary: View changes

Removed reference to 'Email' module adding support for emailfield or an equivalent HTML5 email field. Turns out, it doesn't.

TomPenzer’s picture

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;

TomPenzer’s picture

Status: Active » Needs review

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.

TomPenzer’s picture

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')){

gcb’s picture

Status: Needs review » Closed (fixed)

Included in latest release. Thanks @TomPenzer!

gcb’s picture

Issue summary: View changes

Add note about questionable Drupal 8 support