Skip to content

Instantly share code, notes, and snippets.

@marisqaporter
Last active May 23, 2018 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marisqaporter/c6a5e67de25bd002a2e6cd8a794cb554 to your computer and use it in GitHub Desktop.
Save marisqaporter/c6a5e67de25bd002a2e6cd8a794cb554 to your computer and use it in GitHub Desktop.
to change the search words in drupal search form
/*replace Drupal.hermio.setInputPlaceHolder('search_block_form', 'Keywords', '#search-block-form'); */
/*with */
Drupal.hermio.setInputPlaceHolder('search_block_form', 'Search', '#search-block-form');
/**
* marisa's hook_form_FORM_ID_alter
*CHANGE THE NAME OF THE THEME IN THE FUNCTION
*/
function jvn6_form_search_block_form_alter(&$form, &$form_state, $form_id) {
// Add extra attributes to the text box
$form['search_block_form']['#attributes']['onblur'] = "if (this.value == '') {this.value = 'Search';}";
$form['search_block_form']['#attributes']['onfocus'] = "if (this.value == 'Search') {this.value = '';}";
// Prevent user from searching the default text
$form['#attributes']['onsubmit'] = "if(this.search_block_form.value=='Search'){ alert('Please enter a search phrase.'); return false; }";
// Alternative (HTML5) placeholder attribute instead of using the javascript
$form['search_block_form']['#attributes']['placeholder'] = t('Search');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment