-3

結果がない場合は、検索語(fooの意味など)をフォームに送信したい

詳細:

「検索結果が見つかりません」というelseメッセージを表示するよりも検索結果がある場合のifelse条件の検索機能があります

「検索結果が見つかりません」を1つのフォーム送信で変更したい場合、値はユーザーが検索しようとする検索用語になります。それで...

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 }

.......

これは私が働いている部分です。実際のファイルが長すぎます。

4

2 に答える 2

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>

}
于 2012-10-05T18:53:57.500 に答える
0

では、もう一度試してみましょう。私の主張は、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
    }
}

Assuming cUrl is an option for you. If not, then go with the jquery option others have mentioned.

于 2012-10-05T19:03:16.930 に答える