Agregando campos de html5 en Drupal 7 para poder utilizar los tipos de campos HTML5 de forma facil podemos implementar un hook_theme. para sobreescribir el theme por defecto del textfield.
Implementar el hook_theme y Utilizando en un formulario.
<?php /** * Implements hook_theme */ function my_module_theme() { return array( 'textfield_number' => array( 'render element' => 'element', ), ); } /** * Body theme. */ function theme_textfield_number($variables) { $element = $variables['element']; $element['#attributes']['type'] = 'number'; // change for: (email, date, month...) http://www.w3schools.com/html/html5_form_input_types.asp element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-text')); $extra = ''; $output = '<input' . drupal_attributes($element['#attributes']) . ' />'; return $output . $extra; } function my_module_form_demo($form, &$form_state) { $form['field_number'] = array( '#type' => 'textfield', '#title' => t('Field'), '#theme' => 'textfield_number', ); return $form; }
print "Mas información en: http://www.jeissonp.com/site/blogs/campos-html5-en-drupal-7"