Question

J'utilise une version personnalisée de la recherche-theme-form.tpl Lorsque j'utilise la boîte de recherche, je ne suis transféré à la page de recherche. Mais la recherche ne prend pas réellement. La zone de recherche sur la page de résultats de recherche fonctionne bien. Ceci est mon fichier de recherche-les-form.tpl.php ( demo :

<input type="text" name="search_theme_form_keys" id="edit-search-theme-form-keys" value="Search" title="Enter the terms you wish to search for" class="logininput" height="24px" onblur="restoreSearch(this)" onfocus="clearInput(this)" />
  <input type="submit" name="op" id="edit-submit" value="" class="form-submit" style="display: none;" />
  <input type="hidden" name="form_token" id="edit-search-theme-form-form-token" value="<?php print drupal_get_token('search_theme_form'); ?>" />
  <input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form" />

Il y a aussi un fichier javascript impliqué. Je suppose que l'utilisation de c'est assez clair à partir du code:

 function trim(str) {  
     return str.replace(/^\s+|\s+$/g, '');  
 }  

 function clearInput(e) {  

        e.value="";                // clear default text when clicked  
    e.className="longininput_onfocus"; //change class

 }  

 function restoreSearch(e) {  
    if (trim(e.value) == '') {  
        {
   e.value="Search";             // reset default text onBlur 
         e.className="logininput";        //reset class
  } 
    }  
 }

Quel peut être le problème et comment puis-je résoudre ce problème?

Était-ce utile?

La solution

Apparemment, vous ne pouvez pas modifier directement le code HTML dans search-theme-form.tpl.php depuis thats pas la bonne façon de le faire. Donc, ma classe et la ajoutant onFocus et onBlur attributs était le problème.

La bonne façon de le faire est de modifier les thèmes fichier template.php. Fondamentalement, nous utiliserons form_alter () pour modifier les éléments de formulaire. Depuis que nous utilisons la façon dont HTML est faux. Jetez un oeil sur le code ci-dessous (extrait de: )

<?php
/**
* Override or insert PHPTemplate variables into the search_theme_form template.
*
* @param $vars
*   A sequential array of variables to pass to the theme template.
* @param $hook
*   The name of the theme function being called (not used in this case.)
*/
function yourthemename_preprocess_search_theme_form(&$vars, $hook) {
  // Note that in order to theme a search block you should rename this function
  // to yourthemename_preprocess_search_block_form and use
  // 'search_block_form' instead of 'search_theme_form' in the customizations
  // bellow.

  // Modify elements of the search form
  $vars['form']['search_theme_form']['#title'] = t('');

  // Set a default value for the search box
  $vars['form']['search_theme_form']['#value'] = t('Search this Site');

  // Add a custom class and placeholder text to the search box
  $vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 
                                                              'onfocus' => "if (this.value == 'Search this Site') {this.value = '';}",
                                                              'onblur' => "if (this.value == '') {this.value = 'Search this Site';}");

  // Change the text on the submit button
  //$vars['form']['submit']['#value'] = t('Go');

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_theme_form']['#printed']);
  $vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

  $vars['form']['submit']['#type'] = 'image_button';
  $vars['form']['submit']['#src'] = path_to_theme() . '/images/search.jpg';

  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);

  // Collect all form elements to make it easier to print the whole form.
  $vars['search_form'] = implode($vars['search']);
}
?>

Dans yourthemename_preprocess_search_theme_form - « yourthemename » reflète évidemment le nom de votre thème personnalisé. Fondamentalement, le code est explicite. ce avec les commentaires et tous.

Alors, au fond thats la façon dont il fonctionne.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top