【发布时间】:2017-02-13 14:44:08
【问题描述】:
我是 PHP 新手,有一个小问题。我正在尝试使用两个参数设置一个获取请求。例如,该 URL 应如下所示:
search.php?query=Harry+Potter&page=movies
问题是,我从两种不同的表单中获取了两个参数“查询”和“页面”。
我的代码如下:
表格一:
<form action="search.php" method="get" class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="query">
<div class="input-group-btn">
<button class="btn btn-default c-nav-btn-height" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
表格2:
<form class="btn-group-vertical" action="search.php" method="get">
<button id="bMovies" class="btn active-menu" type="submit" name="page" value="movies">Filme</button>
<button id="bSeries" class="btn" type="submit" name="page" value="series">Serien</button>
</form>
是否有可能将两种形式合并到一个 get Request 中?
【问题讨论】:
-
第一个请求可能使用会话或cookie,每个请求只能执行一个请求。
-
如果您希望同时提交两个表单并包含两个表单的数据,为什么还要创建两个表单?
-
为什么要使用不同的表格?
-
@MagnusEriksson 问题是我有一个搜索字段,在我的描述中是“表格 1”。这个搜索字段位于我网站的每个页面上。如果我提交此表单,它会将数据发送到 search.php,我可以在其中选择两个选项,“电影”和“系列”。这两个选项是我的第二种形式。
-
@C0dekid 这不是我想要做的,两个参数都必须在 URL 中......无论如何,谢谢你的回答