dsns47611 2013-02-26 20:03
浏览 38
已采纳

在页面重新加载时将两个变量传递给URL

On my page, I have two dropdown boxes: One for a list of dates, and one for options. The box for dates is populated as such:

echo "<form name='selectedDate' action='page.php' method='GET' class='auto-style1'>";
echo "<select name='date' onchange='this.form.submit()'>";
echo "<option value=select>Select a Date</option>";
while ($row = mysql_fetch_array($result))
{
    $date = date("m-d-Y",strtotime($row['date']));

    if($date==date("m-d-Y"))
    {
        echo "<option>TODAY</option>";
    }
    else
    {
        echo "<option>" . $date . "</option>";
    }
}
echo "</select>";

echo "<br />";          
echo "<noscript>";
echo "<input type='submit' value='Select'>";
echo "</noscript>";
echo "</form>";

The other dropdown is populated as:

echo "<form name='selectedFormat' action='page.php' method='GET' class='auto-style1'>";
echo "<select name='option' onchange='this.form.submit()'>";
echo "<option value=select>Select a Option</option>";
echo "<option value=Artist>Artist</option>";
echo "<option value=Song>Song</option>";
echo "</select>";

echo "<br />";          
echo "<noscript>";
echo "<input type='submit' value='Select1'>";
echo "</noscript>";
echo "</form>";

Now, you notice that both of them are set for Submit() upon change. If I change the first one, the URL in the browser becomes page.php?date=02-26-2013, and if I change the second one, the URL in the browser becomes page.php?option=Song.

The problem that I'm having, is that if I change the date to an older date, and then change the option, my page reverts back to the date being the current date. I've tried setting the action to a different URL:

$url = "musicInfo.php?date=" .  $nonFormatedDate . "&option=" . $option;

And I changed both forms to have:

echo "<form action='" . $url . "' method='GET' class='auto-style1'>"; 

If I echo $url;, it correctly displays what the browser URL should be. However, the browser URL is still populated by whichever dropdown I used last.

My question here is, how do I get both variables to be passed upon either submission?

So for instance, if I change the date to be 01-13-2012, and then change the option to Song, how can I ensure that the date will be passed as well? And vice versa. Or, say if I change the date to 01-12-2012, is it possible to have the date dropdown box have this selected upon reload?

Site I'm trying to do: http://www.legendary-immersion.com/random/test.php

  • 写回答

1条回答 默认 最新

  • duanpie2834 2013-02-27 13:20
    关注

    As people say in comment you can submit only one form per request. So the best way is to hide data that you need in your form.

    In your php file add this code

    $date = isset($_GET["date"]) ? $_GET["date"] : "";
    $option = isset($_GET["option"]) ? $_GET["option"] : "";
    

    Then in first form add

    <input type="hidden" name="option" value="<?php echo $option; ?>"/>
    

    And in the second form add

    <input type="hidden" name="date" value="<?php echo $date; ?>"/>
    

    As the result in every form submit you will get the url like

    page.php?date=yourdate&option=youroption
    

    Best regards, Hope this will help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常