单击“提交”后如何存储变量值?

时间:2017-12-06 15:42:01

标签: php forms variables form-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”时,我在网址../index.php?typeAnag=all中获取,并获取表单“filter”../ index.php?filter = word

但我想存储值typeAnag = all并复合我的网址如下:../ index.php?typeAnag = all&amp; filter = word

但是当我点击表单时,我丢失了之前提交的变量值。

我尝试使用$ _SESSION但不起作用。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:-1)

问题是当你点击url中的第二个表单数据时,将只包含来自该表单的元素而不是来自第一个表单,所以如果你想要第二个表单获取有关typeAnag的信息,你需要以第二个形式创建隐藏输入....