Here is some code someone wrote for me (the first section) and I put on my site in search2.tpl (I use Smarty templates). The second code bit is the search form on page ONE of my test site, and the third code bit, the entire template from page TWO (incorporating the code from the first section).
What I want to do is "capture" the input from the form on page ONE (second code section), and then use this data to auto-submit to the form on page TWO (third code section). The code, as is, doesn't error out, and goes to the search page when I type in a search query and click submit, but it doesn't search for the entered text or do anything except maybe refresh itself.
Anyone have any ideas?
What I want to do is "capture" the input from the form on page ONE (second code section), and then use this data to auto-submit to the form on page TWO (third code section). The code, as is, doesn't error out, and goes to the search page when I type in a search query and click submit, but it doesn't search for the entered text or do anything except maybe refresh itself.
Anyone have any ideas?
Code:
<script type="text/javascript">
<!--
function checkForAutoSearch()
{
var searchString = <?php echo (!empty($_POST['new_search_text'])) ? $_POST['new_search_text'] : ''; ?>;
if (searchString)
{
// put searchString into the second search field
document.getElementById('search_text').value = searchString;
// up in your search form, assign the form tag an id first: id="search_form_new"
// then submit the form:
document.getElementById('search_form_new').submit();
}
}
// now fire this function whenever the page loads
window.onload = checkForAutoSearch;
//-->
</script>
-------------
<form id="searchForm_newsearch" action="./search2.php" method="post"><input type="text" name="new_search_text" value=""><input type="submit" value="Search"><input type="submit" value="Cancel" onclick="showSearchLink();return false;"></form><a id="searchLink" class="button_link_main" href="./search2.php" onclick="showSearchForm();return false;"><img src="/images/search.png" onmouseover="this.src='/images/searchsite_hover.png'" onmouseout="this.src='/images/search.png'" /></a>
--------------
{literal}
<script type="text/javascript">
<!--
function checkForAutoSearch()
{
var searchString = <?php echo (!empty($_POST['new_search_text'])) ? $_POST['new_search_text'] : ''; ?>;
if (searchString)
{
// put searchString into the second search field
document.getElementById('search_text').value = searchString;
// up in your search form, assign the form tag an id first: id="search_form_new"
// then submit the form:
document.getElementById('search_form_new').submit();
}
}
// now fire this function whenever the page loads
window.onload = checkForAutoSearch;
//-->
</script>
{/literal}
<img src='./images/icons/search48.gif' border='0' class='icon_big'>
<div>{lang_print id=924}</div>
<br />
<br />
<form id="search_form_new" action='search2.php' name='search_form' method='post'>
<table cellpadding='0' cellspacing='0' align='center'>
<tr>
<td class='search'>
<table cellpadding='0' cellspacing='0' align='center'>
<tr>
<td>{lang_print id=925}</td>
<td> <input style='background-color:#CCCCCC' type='text' size='30' class='text' name='search_text' id='search_text' value='{$search_text}' maxlength='100'></td>
<td>
<input type='submit' class='button' value='{lang_print id=646}'>
<input type='hidden' name='task' value='dosearch'>
<input type='hidden' name='t' value='0'>
</td>
</tr>
<tr>
<td> </td>
<td colspan='2'> <b>-=<a href='search_advanced.php'>Browse Members</a>=-</b></td>
</tr>
</table>
</div>
</form>
</td>
</tr>
</table>
<br>
{if $search_text != ""}
{if $is_results == 0}
<table cellpadding='0' cellspacing='0' align='center'>
<tr>
<td class='result'>
<img src='./images/icons/bulb16.gif' class='icon'>
{lang_sprintf id=927 1=$search_text}
</td>
</tr>
</table>
{else}
{* SHOW DIFFERENT RESULT TOTALS *}
<table class='tabs' cellpadding='0' cellspacing='0'>
<tr>
<td class='tab0'> </td>
{section name=search_loop loop=$search_objects}
<td class='tab{if $t == $search_objects[search_loop].search_type}1{else}2{/if}' NOWRAP>{if $search_objects[search_loop].search_total == 0}{lang_sprintf id=$search_objects[search_loop].search_lang 1=$search_objects[search_loop].search_total}{else}<a href='search2.php?task=dosearch&search_text={$url_search}&t={$search_objects[search_loop].search_type}'>{lang_sprintf id=$search_objects[search_loop].search_lang 1=$search_objects[search_loop].search_total}</a>{/if}</td>
<td class='tab'> </td>
{/section}
<td class='tab3'> </td>
</tr>
</table>
<div class='search_results'>
{* SHOW PAGES *}
{if $p != 1}<a href='search2.php?task=dosearch&search_text={$url_search}&t={$t}&p={math equation='p-1' p=$p}'>« {lang_print id=182}</a> | {/if}
{if $p_start == $p_end}
<b>{lang_sprintf id=184 1=$p_start 2=$total_results}</b> ({lang_sprintf id=928 1=$search_time})
{else}
<b>{lang_sprintf id=185 1=$p_start 2=$p_end 3=$total_results}</b> ({lang_sprintf id=928 1=$search_time})
{/if}
{if $p != $maxpage} | <a href='search2.php?task=dosearch&search_text={$url_search}&t={$t}&p={math equation='p+1' p=$p}'>{lang_print id=183} »</a>{/if}
<br><br>
{* SHOW RESULTS *}
{section name=result_loop loop=$results}
<div class='search_result{cycle name="class_name" values="1,2,2,1"}' style='width: 400px; float: left; border: 1px solid #CCCCCC; margin: 5px;'>
<table cellpadding='0' cellspacing='0'>
<tr>
<td valign='top' style='padding-right: 4px;'>
<a href="{$results[result_loop].result_url}" class="title"><img src='{$results[result_loop].result_icon}' class='photo' width='60' height='60' border='0'></a>
</td>
<td valign='top'>
<div class='search_result_text'>
{capture assign='result_title'}{lang_sprintf id=$results[result_loop].result_name 1=$results[result_loop].result_name_1}{/capture}
<a href="{$results[result_loop].result_url}" class="title">{$result_title|truncate:40:"...":true}</a>
<div class='search_result_text2'>{lang_sprintf id=$results[result_loop].result_desc 1=$results[result_loop].result_desc_1 2=$results[result_loop].result_desc_2 3=$results[result_loop].result_desc_3}</div>
{if $results[result_loop].result_online == 1}<div style='margin-top: 5px;'><img src='./images/icons/online16.gif' border='0' class='icon'>{lang_print id=929}</div>{/if}
</div>
</td>
</tr>
</table>
</div>
{cycle name="clear_cycle" values=",<div style='clear: both; height: 0px;'></div>"}
{/section}
<div style='clear:both;'></div><br />
{* SHOW PAGES *}
{if $p != 1}<a href='search2.php?task=dosearch&search_text={$url_search}&t={$t}&p={math equation='p-1' p=$p}'>« {lang_print id=182}</a> | {/if}
{if $p_start == $p_end}
<b>{lang_sprintf id=184 1=$p_start 2=$total_results}</b> ({lang_sprintf id=928 1=$search_time})
{else}
<b>{lang_sprintf id=185 1=$p_start 2=$p_end 3=$total_results}</b> ({lang_sprintf id=928 1=$search_time})
{/if}
{if $p != $maxpage} | <a href='search2.php?task=dosearch&search_text={$url_search}&t={$t}&p={math equation='p+1' p=$p}'>{lang_print id=183} »</a>{/if}
</div>
{/if}
{/if}