I'm onto a project and have been stuck at a simple problem that needs a simple solution where i badly need help. I'm trying to design a form where there will be a drop down list with "google", "yahoo" and "bing" as the options and when the user clicks on the submit button the text entered in the text box will be searched in the corresponding website (like google or yahoo or bing ). Here is the code. echo "<form class=\"form\" METHOD=\"GET\" ACTION=\"http://www.google.com/search\" TARGET=\"_blank\"\">"; echo "<input type=\"Text\" name=\"q\" size=\"25\" maxlength=\"255\" class=\"Ft\">\n"; echo "</td>\n"; echo "\n"; echo "<td valign=\"baseline\" style=\"background-color:#E6EAE9;\">\n"; echo "<div class=\"styled\"> \n"; echo "<select>\n"; echo " <option value=\"Google\">Google</option>\n"; echo " <option value=\"Yahoo\">Yahoo</option>\n"; echo " <option value=\"Bing\">Bing</option>\n"; echo " \n"; echo "</select>\n"; PHP: What i'm trying to do is that when the user types the text and select the option and then clicks on the submit button it will go to the corrosponding search website google or yahoo or bing. If you have a similar html/php solution to accomplish this please let me know or post the link. Please post your answers or sugesstions and i'd be grateful. Thanks.
This is a nice example of what you need: http://www.draac.com/searchpull.html BTW next time add HTML code between code tags so <?php // here your code ?> <p>here your html <span class="something">code</span></p> <?php // here more code ?> PHP: its more readable for everyone and because you closed the tags you don't use PHP to parse the parts between ?> and <?php so the script will be a tiny bit faster!
Submit to (the "action" part of the form) your own PHP file, not to the search engine directly. In that PHP file, use the value of the select (you'll have to name it and gice the options values) to decide which search engine to use. Then you can find PHP examples for submitting to search engines. BTW, just type your PHP code, don't echo it. There's no reason for the additional overhead of using PHP to generate the static HTML.
$searchquery = $_POST['searchquery']; $googlesearch= "http://www.google.com/#hl=en&tbo=d&sclient=psy-ab&q=" . $searchquery . "&oq=" . $searchquery . "&gs_l=hp.3..0l4.2152.82251.0.82627.292.271.7.6.6.7.708.50700.11j175j52j12j10j3j1.264.0.les%3B..1.0...1c.1.kcULqNj55cQ&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.41524429,d.eWU&fp=c5167c443cd9f80c&biw=1600&bih=799"; what ever word or string comes from your input text box and is submitted it will be picked up as $_POST variable. and will be fit into the google search query string. That way you're making queries from your site. It will send that query to google but you will have to decide how you want the search results to appear on your page. <DIV> table? <IFrame> etc. using google is pretty easy thoughon its own and most search engines allow you to already have your own google search box on your site. Why not use their already created search boxes from those sites?
Here's a simple example for you: page.html <form action="redirect.php" method="post"> <select name="site"> <option value="google">Google</option> <option value="yahoo">Yahoo</option> <option value="bing">Bing</option> </select> <input type="text" name="term" value="Enter Search Term!" onclick="javascript:if(this.value=='Enter Search Term!')this.value=''" onblur="javascript:if(this.value=='')this.value='Enter Search Term!'" /> <input type="submit" value="Search!" /> </form> HTML: redirect.php <?php $valid_choices = array('google','yahoo','bing'); $site = (isset($_POST['site'])) ? $_POST['site'] : ''; $term = (isset($_POST['term'])) ? $_POST['term'] : ''; if ( $site && in_array($site, $valid_choices) ) { switch ($site) { case 'google': $url = 'http://www.google.com/#q=' . $term; break; case 'yahoo': $url = 'http://search.yahoo.com/search?p=' . $term; break; case 'bing': $url = 'http://www.bing.com/search?q=' . $term; break; } header('Location: ' . $url); } else { header('Location: page.html'); } ?> PHP:
Thanks everyone for adequately answering my question. I've solved it myself using all your help. Thanks to omgitsfletch, ezprint2008, rukbat and ericbrugemma.