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,&$form_state) {
$node['primary_email'] = array(
'#type' => 'emailfield',
'#title' => t('Submitter'),
); // in Drupal 8, it's '#type' => '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' => 'My Very Own Module',
'page callback' => 'mymodule_description',
'access callback' => TRUE,
'expanded' => TRUE,
);
// create menu-entry for form:
$items['mymodule/myform'] = array(
'title' => 'My Very Own Form',
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_form'),
'access arguments' => array('Behold, the form.'),
'file' => '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.