PHP - 通过查询字符串传递下拉列表选项

发布于 2024-08-03 16:10:21 字数 77 浏览 1 评论 0原文

我有一个下拉列表,其中包含需要通过查询字符串传递的选项。我该怎么做呢?另外,有人能列出一种使用按钮和不使用按钮来执行此操作的方法吗?谢谢你!

I have a drop down list that has options that need to be passed through a query string. How would I go about doing this? Also, would anyone be able to list a way to do this both using a button and without using a button? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城缀染半城烟沙 2024-08-10 16:10:21
<form method="get">
<select multiple="multiple" name="things[]">
...
</select>
<input type="submit" value="submit"/>
</form>

<?php    
if(isset($_GET['things'])) {
    foreach($_GET['things'] as $thing) {
       echo $thing . '<br />';
    }
}
?>
<form method="get">
<select multiple="multiple" name="things[]">
...
</select>
<input type="submit" value="submit"/>
</form>

<?php    
if(isset($_GET['things'])) {
    foreach($_GET['things'] as $thing) {
       echo $thing . '<br />';
    }
}
?>
风和你 2024-08-10 16:10:21

根据 Jani 的回复,您是否希望在没有按钮的情况下提交表单,但如果用户没有 javascript,仍然有一个备份按钮?您可以使用 noscript 来覆盖:

<form action="script.php" method="get">
     <div>
     <select name="options" onchange="this.form.submit()">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
     </select>
     <noscript>
          <input type="submit" value="Go!" />
     </noscript>
     </div>
</form>

Based on Jani's response, are you wanting to have the form submit without a button but still have a backup button if the user doesn't have javascript? You can use noscript to cover that:

<form action="script.php" method="get">
     <div>
     <select name="options" onchange="this.form.submit()">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
     </select>
     <noscript>
          <input type="submit" value="Go!" />
     </noscript>
     </div>
</form>
香草可樂 2024-08-10 16:10:21

没有按钮:

<form method="get">
<select multiple="multiple" name="things[]" onchange="this.form.submit()">
...
</select>
</form>

Without a button:

<form method="get">
<select multiple="multiple" name="things[]" onchange="this.form.submit()">
...
</select>
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文