如何将变量从一个页面上的输入框传递到另一个页面,然后提交?

时间:2013-08-06 04:02:07

标签: javascript html forms variables submit

这是由本网站的一个有用的成员(第一部分)编写的一些代码,我将我的网站放在search2.tpl中(我使用Smarty模板)。第二个代码位是我的测试站点的第一页上的搜索表单,第三个代码位,第二页的整个模板(包含第一部分的代码)。

我想要做的是“捕获”第1页(第二个代码部分)表单中的输入,然后使用此数据自动提交到第TWO页(第三个代码部分)的表单。代码按原样不会出错,当我输入搜索查询并单击“提交”时,它会进入搜索页面,但它不会搜索输入的文本或执行任何操作,除非刷新本身。

非常感谢任何想法或帮助!

<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} 

0 个答案:

没有答案