2010-05-22 5 views
1

사용자 정의 버전의 search-theme-form.tpl을 사용하고 있습니다. 검색 상자를 사용할 때 검색 페이지로 전송됩니다. 그러나 검색은 실제로 일어나지 않습니다. 검색 결과 페이지의 검색 창은 작동합니다. . 또한 포함 된 자바 스크립트 파일이Drupal - 검색 상자가 작동하지 않습니다 - 사용자 정의 테마 템플리트

<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" /> 

나는 그것을 사용하는 코드에서 꽤 분명하다 추측 : 이것은 내 검색 그들을-form.tpl.php 파일 (demo입니다

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 
    } 
    } 
} 

무엇 문제가 될 수 있으며 어떻게 해결할 수 있습니까?

+0

'search-theme-form.tpl.php' ('...- from.tpl' 대신)을 의미합니까? 기본 템플릿으로 검색 결과를 얻습니까? 사이트를 색인 생성하도록 cron 작업을 설정 했습니까? 사용자가 검색 할 수 있도록 권한을 설정 했습니까? http://drupal.org/handbook/modules/search를 참조하십시오. –

+0

죄송합니다. search-theme-form.tpl.php입니다. 내 잘못이야. 예, 사용자는 검색 권한이 있으며 사이트의 색인이 제대로 생성되었습니다. 나는 화환 테마를 시도하고 완벽하게 작동하는 것 같습니다. – bcosynot

+0

예를 살펴보면 원래 Drupal 검색 양식이 'search/[searchTerm]'을 가리킴에 따라 양식 동작 ('/ whackk /')이 적어도 의심 스럽습니다. 주요 문제는 HTML 마크 업을 통해 처음부터 자신의 양식을 작성하여 완전히 Drupal Forms API를 우회하는 것입니다. 권장하지 않습니다. 표준 Drupal 검색을 변경하려면 어떻게해야합니까? (원하는대로 Drupal 양식을 왜곡하고 조정할 수있는 방법이 많이 있지만 적절한 대답을 얻으려면 목표에 관한 더 많은 정보가 필요합니다.) –

답변

5

올바른 방법이 아니기 때문에 search-theme-form.tpl.php에서 직접 HTML을 수정할 수는 없습니다. 따라서 클래스 및 onFocus 및 onBlur 특성을 추가하는 것이 문제였습니다.

올바른 방법은 파일 template.php을 수정하는 것입니다. 기본적으로 form_alter()를 사용하여 양식 요소를 수정합니다. HTML 방식을 사용하는 것은 잘못된 것이기 때문에. 아래의 코드를 살펴 보자 (에서 촬영 : here)

<?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']); 
} 
?> 

yourthemename_preprocess_search_theme_form에서 - 'yourthemename'분명히 사용자 지정 테마의 이름을 반영합니다. 기본적으로 코드는 자명하다. 모든 의견과 함께.

그래서 기본적으로 작동하는 방식입니다.

+1

+1 질문에 대한 후속/답변 –