单击"Submit"后如何存储变量值?
How to store variable value after clicking "Submit"?
解决方案:
<?php
$typeAnag = filter_input ( INPUT_GET, 'typeAnag', FILTER_SANITIZE_STRING );
$filter = filter_input ( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
?>
<nav class="navbar navbar-light bg-light">
<form class="form-inline">
<button class="btn btn-sm align-middle btn-outline-secondary"
type="submit" name="typeAnag" value="all">All</button>
</form>
<form class="form-inline pull-xs-right" >
<input type="filter" name="filter" id="filter"
class="form-control mr-sm-2" placeholder="Filter...">
<input type="hidden" name="typeAnag" value="<?=$typeAnag?>">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Filtra</button>
</form>
</nav>
我有这个 php 页面有两种形式:
<?php
$typeAnag = filter_input ( INPUT_GET, 'typeAnag', FILTER_SANITIZE_STRING );
$filter = filter_input ( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
?>
<nav class="navbar navbar-light bg-light">
<form class="form-inline">
<button class="btn btn-sm align-middle btn-outline-secondary"
type="submit" name="typeAnag" value="all">All</button>
</form>
<form class="form-inline pull-xs-right" >
<input type="filter" name="filter" id="filter"
class="form-control mr-sm-2" placeholder="Filter...">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Filtra</button>
</form>
</nav>
当我点击提交表单时 "typeAnag" 我在 url ../index.php?typeAnag=all 和表单 "filter" ../index.php?filter=单词
但我想存储值 typeAnag=all 并像这样合成我的 url:../index.php?typeAnag=all&filter=word
但是当我点击表单时,我丢失了之前提交的变量值。
我尝试使用 $_SESSION 但不起作用。
如有任何帮助,我们将不胜感激
问题是当你点击第二个表单时 url 中的数据将只包含来自该表单的元素而不是来自第一个表单的元素所以如果你想在第二个表单中获取有关 typeAnag 的信息你需要在中创建隐藏输入第二种形式....
解决方案:
<?php
$typeAnag = filter_input ( INPUT_GET, 'typeAnag', FILTER_SANITIZE_STRING );
$filter = filter_input ( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
?>
<nav class="navbar navbar-light bg-light">
<form class="form-inline">
<button class="btn btn-sm align-middle btn-outline-secondary"
type="submit" name="typeAnag" value="all">All</button>
</form>
<form class="form-inline pull-xs-right" >
<input type="filter" name="filter" id="filter"
class="form-control mr-sm-2" placeholder="Filter...">
<input type="hidden" name="typeAnag" value="<?=$typeAnag?>">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Filtra</button>
</form>
</nav>
我有这个 php 页面有两种形式:
<?php
$typeAnag = filter_input ( INPUT_GET, 'typeAnag', FILTER_SANITIZE_STRING );
$filter = filter_input ( INPUT_GET, 'filter', FILTER_SANITIZE_STRING );
?>
<nav class="navbar navbar-light bg-light">
<form class="form-inline">
<button class="btn btn-sm align-middle btn-outline-secondary"
type="submit" name="typeAnag" value="all">All</button>
</form>
<form class="form-inline pull-xs-right" >
<input type="filter" name="filter" id="filter"
class="form-control mr-sm-2" placeholder="Filter...">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Filtra</button>
</form>
</nav>
当我点击提交表单时 "typeAnag" 我在 url ../index.php?typeAnag=all 和表单 "filter" ../index.php?filter=单词
但我想存储值 typeAnag=all 并像这样合成我的 url:../index.php?typeAnag=all&filter=word
但是当我点击表单时,我丢失了之前提交的变量值。
我尝试使用 $_SESSION 但不起作用。
如有任何帮助,我们将不胜感激
问题是当你点击第二个表单时 url 中的数据将只包含来自该表单的元素而不是来自第一个表单的元素所以如果你想在第二个表单中获取有关 typeAnag 的信息你需要在中创建隐藏输入第二种形式....