3

I am creating a zen sub theme and I was wondering what't the quickest way to add the x-webkit-speech attribute to the search box so user's can search with their voice? I know there is a Drupal project that can modify the search for me but I would prefer to do it in my templates somewhere so the rendered output is something like...

<input title="Enter the terms you wish to search for." type="text" x-webkit-speech id="edit-search-block-form--2" name="search_block_form" value="" size="15" maxlength="128" class="form-text">

2 Answers 2

1

as described in hook_form_FORM_ID_alter and @tenken said, write a simple module:

function mymodule_form_search_block_form_alter(&$form, $form_state, $form_id) {
  $form['search_block_form']['#attributes']['x-webkit-speech'] = 'x-webkit-speech';
  $form['search_block_form']['#attributes']['speech'] = 'speech';
}

also to have valid xhtml avoid valueless attribute.

2
  • just to be clear you dont need a custom module, since you asked for a "theme" solution. the hook_form functions can be called from your custom theme's template.php file.
    – tenken
    Commented Apr 16, 2012 at 15:49
  • 1
    I used a hybrid of your answer and tenken's. I'm marking yours as the answer because it contained most of the code I used: function THEMENAME_form_search_block_form_alter(&$form, $form_state, $form_id) { $form['search_block_form']['#attributes']['x-webkit-speech'] = 'x-webkit-speech'; $form['search_block_form']['#attributes']['speech'] = 'speech'; }
    – Adam
    Commented Apr 23, 2012 at 18:45
2

use hook_form_alter on the search_form and add an HTML attribute via the #attributes for x-webkit-speech.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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