I want to add the html5 tel attribute to a particular field in my webform form in order to prompt mobile devices to display the appropriate keyboard.

I was trying this:

function my_module_form_alter(&$form, $form_state, $form_id) {

    /* add html5 phone type for phones and smarter devices to use */
    /* usage: just include the word 'phone' in the field title and have the field of type 'textfield' */

    foreach ($form['submitted'] as &$field){
        if (is_array($field) && isset($field['#title']) && stristr(strtolower($field['#title']), 'phone') && isset($field['#type']) && ($field['#type'] == 'textfield')){
            $field['#attributes']['type'] = 'tel';

but the attribute doesn't get applied and the resulting field has the type of "text"

I suspect there may be a hook for webforms that will let me adjust the output, I just can't find it.


Drupal 7 core field doesn't support HTML 5 form elements.

You should try the Elements module to do that.

This module intends to become a repository for advanced form elements. Supports HTML 5 standards like: (url, email, search, tel, number, range)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.