2013-09-25 163 views
0

嗨,大家好我是這個新手,我試圖創建一個搜索表單,但似乎是我的函數php文件的問題。 我知道問題出在我的「if」聲明中,但我不知道是否有任何其他選項可以用來使其工作。下面的代碼:解析錯誤:語法錯誤,意外的'搜索'(T_STRING)

function my_search_form($form) { 
$form = '<form role="search" method="get" id="searchform" action="' . home_url('/') . '" > 
<input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value == . 'search & hit enter' .) { this.value = . '' . ; }" onblur="if(this.value == . '' .) {this.value = . 'search & hit enter' . ; }" /> 
<input type="hidden" value="post" name="post_type" id="post_type" /> 
</form>'; 

return $form; 

}

add_filter('get_search_form', 'my_search_form'); 
+3

您使用單引號既分隔逃脫你的' $ form'字符串,以及裏面的javascript值。你需要用反斜槓來逃避後者。 – andrewsi

回答

0
search & hit enter 

這部分是無效的代碼,它需要

function my_search_form($form) { 
    $form = ' 
    <form role="search" method="get" id="searchform" action="' . home_url('/') . '" > 
     <input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value == \'search &amp; hit enter\') { this.value = \'\'; }" onblur="if(this.value == \'\') {this.value =\'search &amp; hit enter\'; }" /> 
     <input type="hidden" value="post" name="post_type" id="post_type" /> 
    </form>'; 

    return $form; 
} 
+0

它工作。非常感謝你們! – user2815776

相關問題