starhawk85 Posted April 24, 2012 Share Posted April 24, 2012 Hello, I am currently using a pre-built search for my PHP, MySQL web site, I am using Sphider. I have altered the search to display drop down boxes that allow you to select the state and prop type, my question is how can i get the drop down boxes to automaticly fill in the search text box or use the drop downs for search only. here is the php for search. <?php /******************************************* * Sphider Version 1.3.x * This program is licensed under the GNU GPL. * By Ando Saabas ando(a t)cs.ioc.ee ********************************************/ //error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); error_reporting(E_ALL); $include_dir = "./include"; include ("$include_dir/commonfuncs.php"); //extract(getHttpVars()); if (isset($_GET['query'])) $query = $_GET['query']; if (isset($_GET['search'])) $search = $_GET['search']; if (isset($_GET['domain'])) $domain = $_GET['domain']; if (isset($_GET['type'])) $type = $_GET['type']; if (isset($_GET['catid'])) $catid = $_GET['catid']; if (isset($_GET['category'])) $category = $_GET['category']; if (isset($_GET['results'])) $results = $_GET['results']; if (isset($_GET['start'])) $start = $_GET['start']; if (isset($_GET['adv'])) $adv = $_GET['adv']; $include_dir = "./include"; $template_dir = "./templates"; $settings_dir = "./settings"; $language_dir = "./languages"; require_once("$settings_dir/database.php"); require_once("$language_dir/en-language.php"); require_once("$include_dir/searchfuncs.php"); require_once("$include_dir/categoryfuncs.php"); include "$settings_dir/conf.php"; include "$template_dir/$template/header.html"; include "$language_dir/$language-language.php"; if ($type != "or" && $type != "and" && $type != "phrase") { $type = "and"; } if (preg_match("/[^a-z0-9-.]+/", $domain)) { $domain=""; } if ($results != "") { $results_per_page = $results; } if (get_magic_quotes_gpc()==1) { $query = stripslashes($query); } if (!is_numeric($catid)) { $catid = ""; } if (!is_numeric($category)) { $category = ""; } if ($catid && is_numeric($catid)) { $tpl_['category'] = sql_fetch_all('SELECT category FROM '.$mysql_table_prefix.'categories WHERE category_id='.(int)$_REQUEST['catid']); } $count_level0 = sql_fetch_all('SELECT count(*) FROM '.$mysql_table_prefix.'categories WHERE parent_num=0'); $has_categories = 0; if ($count_level0) { $has_categories = $count_level0[0][0]; } require_once("$template_dir/$template/search_form.html"); function getmicrotime(){ list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } function poweredby () { global $sph_messages; //If you want to remove this, please donate to the project at http://www.sphider.eu/donate.php print $sph_messages['Powered by'];?> <a href="http://www.sphider.eu/"><img src="sphider-logo.png" border="0" style="vertical-align: middle" alt="Sphider"></a> <?php } function saveToLog ($query, $elapsed, $results) { global $mysql_table_prefix; if ($results =="") { $results = 0; } $query = "insert into ".$mysql_table_prefix."query_log (query, time, elapsed, results) values ('$query', now(), '$elapsed', '$results')"; mysql_query($query); echo mysql_error(); } switch ($search) { case 1: if (!isset($results)) { $results = ""; } $search_results = get_search_results($query, $start, $category, $type, $results, $domain); require("$template_dir/$template/search_results.html"); break; default: if ($show_categories) { if ($_REQUEST['catid'] && is_numeric($catid)) { $cat_info = get_category_info($catid); } else { $cat_info = get_categories_view(); } require("$template_dir/$template/categories.html"); } break; } include "$template_dir/$template/footer.html"; ?> here is the HTML form <center> <table cellpadding="5" cellspacing="1" class="searchBox"> <tr> <td align="center"> <form action="search.php" method="get"> <table><tr><td> <div align="left"> <input type="text" name="query" id="query" size="40" value="<?php print quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500"> <form action="" method ="post"> <input type="text" name="search"> <select name="state"> <option value="Nation Wide"> Nation Wide </option> <option value="Nation Wide ex AK/HI"> Nation Wide ex AK & HI </option> <option value="Alabama"> Alabama </option> <option value="Alaska"> Alaska </option> <option value="Arizona"> Arizona </option> <option value="Arkansas"> Arkansas </option> <option value="California"> California </option> <option value="Colorado"> Colorado </option> <option value="Connecticut"> Connecticut </option> <option value="Deleware"> Deleware </option> <option value="Florida"> Florida </option> <option value="Georgia"> Georgia </option> <option value="Hawaii"> Hawaii </option> <option value="Idaho"> Idaho </option> <option value="Illinois"> Illinois </option> <option value="Indiana"> Indiana </option> <option value="Iowa"> Iowa </option> <option value="Kansas"> Kansas </option> <option value="Kentucky"> Kentucky </option> <option value="Louisiana"> Louisiana </option> <option value="Maine"> Maine </option> <option value="Maryland"> Maryland </option> <option value="Massachusetts"> Massachusetts </option> <option value="Michigan"> Michigan </option> <option value="Minnesota"> Minnesota </option> <option value="Mississippi"> Mississippi </option> <option value="Missouri"> Missouri </option> <option value="Montana"> Montana </option> <option value="Nebraska"> Nebraska </option> <option value="Nevada"> Nevada </option> <option value="New Hampshire"> New Hampshire </option> <option value="New Jersey"> New Jersey </option> <option value="New Mexico"> New Mexico </option> <option value="New York"> New York </option> <option value="North Carolina"> North Carolina </option> <option value="North Dakota"> North Dakota </option> <option value="Ohio"> Ohio </option> <option value="Oklahoma"> Oklahoma </option> <option value="Oregon"> Oregon </option> <option value="Pennsylvania"> Pennsylvania </option> <option value="Rhode Island"> Rhode Island </option> <option value="South Carolina"> South Carolina </option> <option value="South Dakota"> South Dakota </option> <option value="Tennessee"> Tennessee </option> <option value="Texas"> Texas </option> <option value="Utah"> Utah </option> <option value="Vermont"> Vermont </option> <option value="Virginia"> Virginia </option> <option value="Washington"> Washington </option> <option value="West Virginia"> West Virginia </option> <option value="Wisconsin"> Wisconsin </option> <option value="Wyoming"> Wyoming </option> </select> <select name="prop"> <option value="Downtown or Streetfront"> Downtown or Streetfront </option> <option value="Freestanding Pad"> Freestanding Pad </option> <option value="Lifestyle Center"> Lifestyle Center </option> <option value="Mall or Food Court"> Mall or Food Court </option> <option value="Nontraditional Units"> Nontraditional Units </option> <option value="Power Center"> Power Center </option> <option value="Shopping Center"> Shopping Center </option> <option value="Entertainment Center"> Entertainment Center </option> <option value="Manufacturer Outlet Center"> Manafacturer Outlet Center </option> <option value="Regional Mall"> Regional Mall </option> </select> <input type="submit" name="submit" value="search"> </form> </div> <td> <input type="submit" value="<?php print $sph_messages['Search']?>"> </td></tr></table> <?php if ($adv==1 || $advanced_search==1) { ?> <table width = "100%"> <tr> <td width="40%"><input type="radio" name="type" value="and" <?php print $type=='and'?'checked':''?>><?php print $sph_messages['andSearch']?></td> <td><input type="radio" name="type" value="or" <?php print $_REQUEST['type']=='or'?'checked':''?>><?php print $sph_messages['orSearch']?></td></tr> <tr> <td><input type="radio" name="type" value="phrase" <?php print $_REQUEST['type']=='phrase'?'checked':''?>><?php print $sph_messages['phraseSearch']?></td> <td><?php print $sph_messages['show']?> <select name='results'> <option <?php if ($results_per_page==10) echo "selected";?>>10</option> <option <?php if ($results_per_page==20) echo "selected";?>>20</option> <option <?php if ($results_per_page==50) echo "selected";?>>50</option> <option <?php if ($results_per_page==100) echo "selected";?>>100</option> </select> <?php print $sph_messages['resultsPerPage']?> </td> </tr> </table> <?php }?> <?php if ($catid<>0){?> <center><b><?php print $sph_messages['Search']?></b>: <input type="radio" name="category" value="<?php print $catid?>"><?php print $sph_messages['Only in category']?> "<?php print $tpl_['category'][0]['category']?>'" <input type="radio" name="category" value="-1" checked><?php print $sph_messages['All sites']?></center> <?php }?> <input type="hidden" name="search" value="1"> </form> <?php if ($has_categories && $search==1 && $show_categories){?> <a href="search.php"><?php print $sph_messages['Categories']?></a> <?php }?> </td> </tr> </table> </center> I just assume my error is here in the HTML... Any help would be more than appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/261545-search-submission/ Share on other sites More sharing options...
MarPlo Posted April 24, 2012 Share Posted April 24, 2012 Hi, Try this; add the following code in the <select> tag: onchange="document.getElementById('query').value=this.value;" This code adds the selected option in the element with id="query". Quote Link to comment https://forums.phpfreaks.com/topic/261545-search-submission/#findComment-1340184 Share on other sites More sharing options...
starhawk85 Posted April 24, 2012 Author Share Posted April 24, 2012 Hi, Try this; add the following code in the <select> tag: onchange="document.getElementById('query').value=this.value;" This code adds the selected option in the element with id="query". What part of the code are you looking at? Whare would i apply this? Quote Link to comment https://forums.phpfreaks.com/topic/261545-search-submission/#findComment-1340185 Share on other sites More sharing options...
starhawk85 Posted April 24, 2012 Author Share Posted April 24, 2012 Okay so i have the following code and have placed the code you provided to me in appropriate spots, and it works. I now have the following. I have changed BOLD RED <center> <table cellpadding="5" cellspacing="1" class="searchBox"> <tr> <td align="center"> <form action="search.php" method="get"> <table><tr><td> <div align="left"> <input type="text" name="query" id="query" size="40" value="<?php print quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500"> <form action="" method ="post"> <input type="text" name="search"> <select name="state" onchange="document.getElementById('query').value=this.value;"> <option value="Nation Wide"> Nation Wide </option> <option value="Nation Wide ex AK/HI"> Nation Wide ex AK & HI </option> <option value="Alabama"> Alabama </option> <option value="Alaska"> Alaska </option> <option value="Arizona"> Arizona </option> <option value="Arkansas"> Arkansas </option> <option value="California"> California </option> <option value="Colorado"> Colorado </option> <option value="Connecticut"> Connecticut </option> <option value="Deleware"> Deleware </option> <option value="Florida"> Florida </option> <option value="Georgia"> Georgia </option> <option value="Hawaii"> Hawaii </option> <option value="Idaho"> Idaho </option> <option value="Illinois"> Illinois </option> <option value="Indiana"> Indiana </option> <option value="Iowa"> Iowa </option> <option value="Kansas"> Kansas </option> <option value="Kentucky"> Kentucky </option> <option value="Louisiana"> Louisiana </option> <option value="Maine"> Maine </option> <option value="Maryland"> Maryland </option> <option value="Massachusetts"> Massachusetts </option> <option value="Michigan"> Michigan </option> <option value="Minnesota"> Minnesota </option> <option value="Mississippi"> Mississippi </option> <option value="Missouri"> Missouri </option> <option value="Montana"> Montana </option> <option value="Nebraska"> Nebraska </option> <option value="Nevada"> Nevada </option> <option value="New Hampshire"> New Hampshire </option> <option value="New Jersey"> New Jersey </option> <option value="New Mexico"> New Mexico </option> <option value="New York"> New York </option> <option value="North Carolina"> North Carolina </option> <option value="North Dakota"> North Dakota </option> <option value="Ohio"> Ohio </option> <option value="Oklahoma"> Oklahoma </option> <option value="Oregon"> Oregon </option> <option value="Pennsylvania"> Pennsylvania </option> <option value="Rhode Island"> Rhode Island </option> <option value="South Carolina"> South Carolina </option> <option value="South Dakota"> South Dakota </option> <option value="Tennessee"> Tennessee </option> <option value="Texas"> Texas </option> <option value="Utah"> Utah </option> <option value="Vermont"> Vermont </option> <option value="Virginia"> Virginia </option> <option value="Washington"> Washington </option> <option value="West Virginia"> West Virginia </option> <option value="Wisconsin"> Wisconsin </option> <option value="Wyoming"> Wyoming </option> </select> <select name="prop" onchange="document.getElementById('query').value=this.value;"> <option value="Downtown or Streetfront"> Downtown or Streetfront </option> <option value="Freestanding Pad"> Freestanding Pad </option> <option value="Lifestyle Center"> Lifestyle Center </option> <option value="Mall or Food Court"> Mall or Food Court </option> <option value="Nontraditional Units"> Nontraditional Units </option> <option value="Power Center"> Power Center </option> <option value="Shopping Center"> Shopping Center </option> <option value="Entertainment Center"> Entertainment Center </option> <option value="Manufacturer Outlet Center"> Manafacturer Outlet Center </option> <option value="Regional Mall"> Regional Mall </option> </select> <input type="submit" name="submit" value="search"> </form> </div> <td> <input type="submit" value="<?php print $sph_messages['Search']?>"> </td></tr></table> <?php if ($adv==1 || $advanced_search==1) { ?> <table width = "100%"> <tr> <td width="40%"><input type="radio" name="type" value="and" <?php print $type=='and'?'checked':''?>><?php print $sph_messages['andSearch']?></td> <td><input type="radio" name="type" value="or" <?php print $_REQUEST['type']=='or'?'checked':''?>><?php print $sph_messages['orSearch']?></td></tr> <tr> <td><input type="radio" name="type" value="phrase" <?php print $_REQUEST['type']=='phrase'?'checked':''?>><?php print $sph_messages['phraseSearch']?></td> <td><?php print $sph_messages['show']?> <select name='results'> <option <?php if ($results_per_page==10) echo "selected";?>>10</option> <option <?php if ($results_per_page==20) echo "selected";?>>20</option> <option <?php if ($results_per_page==50) echo "selected";?>>50</option> <option <?php if ($results_per_page==100) echo "selected";?>>100</option> </select> <?php print $sph_messages['resultsPerPage']?> </td> </tr> </table> <?php }?> <?php if ($catid<>0){?> <center><b><?php print $sph_messages['Search']?></b>: <input type="radio" name="category" value="<?php print $catid?>"><?php print $sph_messages['Only in category']?> "<?php print $tpl_['category'][0]['category']?>'" <input type="radio" name="category" value="-1" checked><?php print $sph_messages['All sites']?></center> <?php }?> <input type="hidden" name="search" value="1"> </form> <?php if ($has_categories && $search==1 && $show_categories){?> <a href="search.php"><?php print $sph_messages['Categories']?></a> <?php }?> </td> </tr> </table> </center> Now i get two search text boxes and two submit search buttons. (View Attachment) How do i get rid of the new text box. Allow both drop downs to be placed in search. Add ,SPACE (, ) to separate the inputs from drop downs. I believe this would finalize my questions... Quote Link to comment https://forums.phpfreaks.com/topic/261545-search-submission/#findComment-1340198 Share on other sites More sharing options...
starhawk85 Posted April 24, 2012 Author Share Posted April 24, 2012 Okay another run, I sould really try to solve for x first before post. I fixed the extra text box and extra submit button problem Here is my code <center> <table cellpadding="5" cellspacing="1" class="searchBox"> <tr> <td align="center"> <form action="search.php" method="get"> <table><tr><td> <div align="left"> <input type="text" name="query" id="query" size="40" value="<?php print quote_replace($query);?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500"> <form action="" method ="post"> <p> <select name="state" onchange="document.getElementById('query').value=this.value;"> <option value="Nation Wide"> Nation Wide </option> <option value="Nation Wide ex AK/HI"> Nation Wide ex AK & HI </option> <option value="Alabama"> Alabama </option> <option value="Alaska"> Alaska </option> <option value="Arizona"> Arizona </option> <option value="Arkansas"> Arkansas </option> <option value="California"> California </option> <option value="Colorado"> Colorado </option> <option value="Connecticut"> Connecticut </option> <option value="Deleware"> Deleware </option> <option value="Florida"> Florida </option> <option value="Georgia"> Georgia </option> <option value="Hawaii"> Hawaii </option> <option value="Idaho"> Idaho </option> <option value="Illinois"> Illinois </option> <option value="Indiana"> Indiana </option> <option value="Iowa"> Iowa </option> <option value="Kansas"> Kansas </option> <option value="Kentucky"> Kentucky </option> <option value="Louisiana"> Louisiana </option> <option value="Maine"> Maine </option> <option value="Maryland"> Maryland </option> <option value="Massachusetts"> Massachusetts </option> <option value="Michigan"> Michigan </option> <option value="Minnesota"> Minnesota </option> <option value="Mississippi"> Mississippi </option> <option value="Missouri"> Missouri </option> <option value="Montana"> Montana </option> <option value="Nebraska"> Nebraska </option> <option value="Nevada"> Nevada </option> <option value="New Hampshire"> New Hampshire </option> <option value="New Jersey"> New Jersey </option> <option value="New Mexico"> New Mexico </option> <option value="New York"> New York </option> <option value="North Carolina"> North Carolina </option> <option value="North Dakota"> North Dakota </option> <option value="Ohio"> Ohio </option> <option value="Oklahoma"> Oklahoma </option> <option value="Oregon"> Oregon </option> <option value="Pennsylvania"> Pennsylvania </option> <option value="Rhode Island"> Rhode Island </option> <option value="South Carolina"> South Carolina </option> <option value="South Dakota"> South Dakota </option> <option value="Tennessee"> Tennessee </option> <option value="Texas"> Texas </option> <option value="Utah"> Utah </option> <option value="Vermont"> Vermont </option> <option value="Virginia"> Virginia </option> <option value="Washington"> Washington </option> <option value="West Virginia"> West Virginia </option> <option value="Wisconsin"> Wisconsin </option> <option value="Wyoming"> Wyoming </option> </select> <select name="prop" onchange="document.getElementById('query').value=this.value;"> <option value="Downtown or Streetfront"> Downtown or Streetfront </option> <option value="Freestanding Pad"> Freestanding Pad </option> <option value="Lifestyle Center"> Lifestyle Center </option> <option value="Mall or Food Court"> Mall or Food Court </option> <option value="Nontraditional Units"> Nontraditional Units </option> <option value="Power Center"> Power Center </option> <option value="Shopping Center"> Shopping Center </option> <option value="Entertainment Center"> Entertainment Center </option> <option value="Manufacturer Outlet Center"> Manafacturer Outlet Center </option> <option value="Regional Mall"> Regional Mall </option> </select> <input type="submit" name="submit" value="search"> </p> </form> </div> <td> </td></tr></table> <?php if ($adv==1 || $advanced_search==1) { ?> <table width = "100%"> <tr> <td width="40%"><input type="radio" name="type" value="and" <?php print $type=='and'?'checked':''?>><?php print $sph_messages['andSearch']?></td> <td><input type="radio" name="type" value="or" <?php print $_REQUEST['type']=='or'?'checked':''?>><?php print $sph_messages['orSearch']?></td></tr> <tr> <td><input type="radio" name="type" value="phrase" <?php print $_REQUEST['type']=='phrase'?'checked':''?>><?php print $sph_messages['phraseSearch']?></td> <td><?php print $sph_messages['show']?> <select name='results'> <option <?php if ($results_per_page==10) echo "selected";?>>10</option> <option <?php if ($results_per_page==20) echo "selected";?>>20</option> <option <?php if ($results_per_page==50) echo "selected";?>>50</option> <option <?php if ($results_per_page==100) echo "selected";?>>100</option> </select> <?php print $sph_messages['resultsPerPage']?> </td> </tr> </table> <?php }?> <?php if ($catid<>0){?> <center><b><?php print $sph_messages['Search']?></b>: <input type="radio" name="category" value="<?php print $catid?>"><?php print $sph_messages['Only in category']?> "<?php print $tpl_['category'][0]['category']?>'" <input type="radio" name="category" value="-1" checked><?php print $sph_messages['All sites']?></center> <?php }?> <input type="hidden" name="search" value="1"> </form> <?php if ($has_categories && $search==1 && $show_categories){?> <a href="search.php"><?php print $sph_messages['Categories']?></a> <?php }?> </td> </tr> </table> </center> View attachment to see view. i am still unable to apply both drop downs to the search and seperate by (, ) ,SPACE how would i go about this? Quote Link to comment https://forums.phpfreaks.com/topic/261545-search-submission/#findComment-1340200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.