How to set type="email" attribute on a Drupal form textfield I'm doing some mobile forms with Drupal and have an email address textfield that currently has type="text" in the resulting HTML. I'd like this to be type="email" instead so that iOS shows a more useful keyboard when entering the email address.

I tried adding:

"#attributes" =&gt; array("type" =&gt; "email")


to my field but it seems to just get ignored by Drupal. Is there a correct and/or supported way to achieve this?
Elements which are input[type=email] are a builtin as of Drupal 8. They can be added (along with other HTML5 elements and markup) to Drupal 6 or 7 via the Elements module. 

As of writing this answer, I found the Element-module docs quite scant; they don't explain that the method for getting an e-mail input-element is slightly different than how it's done in D8. For Drupal 7:

/** 
 * Implements hook_form().
 * "For long-lasting relief you can count on!"
 *
 * hook_form() functions are passed a form-node,
 * plus extra state-info if present.
 * 
 * At the end of the function, the form-node should
 * be returned to the caller.
 *
 */
function mymodule_form($node,&amp;$form_state) {

    $node['primary_email'] = array(
        '#type' =&gt; 'emailfield',
        '#title' =&gt; t('Submitter'),
    ); // in Drupal 8, it's '#type' =&gt; 'email'

    return $node;
}


Be sure to have the Elements module enabled before you expect the above to work. Also, if you haven't already, you'll also want to make the form accessible by doing something like:

/**
 * Implements hook_menu().
 * "Money back guarantee!"
 */
function mymodule_menu() {

    // create primary menu-entry for module:
    $items['mymodule'] = array(
        'title' =&gt; 'My Very Own Module',
        'page callback' =&gt; 'mymodule_description',
        'access callback' =&gt; TRUE,
        'expanded' =&gt; TRUE,
    );

    // create menu-entry for form:
    $items['mymodule/myform'] = array(
        'title' =&gt; 'My Very Own Form',
        'page callback' =&gt; 'drupal_get_form',
        'page arguments' =&gt; array('mymodule_form'),
        'access arguments' =&gt; array('Behold, the form.'),
        'file' =&gt; 'mymodule.module',
    );

    // ...[maybe add more stuff here]...

    return $items;


The other elements made available by Element are listed at cgit.drupalcode.org/elements/tree/elements.module#n7.