2012-10-05 30 views
-3

我要提交的搜索字詞(如什麼呢富表示)爲形式,如果沒有造成如果沒有搜索結果報送形式

詳細搜索詞:

我有一個搜索功能,用的if else條件,如果有搜索結果比顯示其他消息與「沒有搜索結果找到」

我要改變「沒有搜索結果找到」與一個表單提交其中價值將任何搜索術語用戶試圖找到。所以...

if search result found { 
//display result 
} else { 
    // auto submit below form if above condition is not true (means if no search result found) 

    <form action="to url" method="post"> 
    <input name="title" type="text" /> 
    </form> 
} 

以上是我用來提交表格。

編輯:

下面是實際的代碼

....... 

if (count($results)) 
      $qa_content['title']=qa_lang_html_sub('main/results_for_x', qa_html($inquery)); 
     else { ?> 

      <form id="nosearch" method="POST" action="<?php echo qa_opt('site_url'); ?>ask" class="top-askbox" > 
        <input name="title" type="text" value="<?php echo $inquery; ?>"> 
      </form> 
      <script>$("#nosearch").submit();</script> 

     <?php } 

....... 

這就是我工作的部分。實際文件太長。

+2

是什麼問題?或者你有問題? – GBD

+0

如果沒有帶搜索詞的搜索結果作爲值,我該如何自動提交表格 –

+0

使用javascript發佈表格 – GBD

回答

1

您可以使用類似這樣

if (is in search) { 
//display result 
} else { 
    // auto submit below form if above condition is not true (means if no search result found) 

    <form action="to url" id="main" method="post"> 
    <input name="title" type="text" value="$value" /> 
    </form> 
<script>$("#main").submit();</script> 

} 
+0

假設他們正在使用jquery ......但爲什麼不只是使用捲曲?爲什麼即使打擾前端黑客? –

+0

我嘗試了上面的代碼,但它正在輸出值不提交的文本字段。任何想法? –

+0

@pixelngrain你能顯示一些代碼嗎?或者是否包含了juqery或ready函數? – StaticVariable

0

好吧,讓我們再次嘗試。我arguement是,它是荒謬的有前端自動發佈表單時,你可以輕鬆地處理在PHP ...

if (count($results)) 
    $qa_content['title']=qa_lang_html_sub('main/results_for_x', qa_html($inquery)); 
else { 
    $url = 'http://whatever.com/your-search-file.php'; 
    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL, $url); 
    curl_setopt($ch,CURLOPT_POST, count($_POST)); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST)); 
    $result = curl_exec($ch); 
    curl_close($ch); 

    if($results) 
    { 
     //echo results or do whatever 
    } 
    else 
    { 
     // your auto post failed. deal with it 
    } 
} 

假設捲曲是一個選擇。如果沒有,那麼去其他人提到的jquery選項。

+0

讓我試試這個意思,而你可以看到我的編輯與我正在工作的實際代碼...'$ inquery'是變量得到搜索tearm –

+0

它也是不提交,但它是使用搜索詞呈現文本元素 –