Home How to store variable value after clicking "Submit"?
Reply: 1

How to store variable value after clicking "Submit"?

dogshort
1#
dogshort Published in 2017-12-06 15:42:01Z

Solution:

<?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>

I have this php page with two forms:

<?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>

When I click the submit form "typeAnag" I obtain in the url ../index.php?typeAnag=all and for the form "filter" ../index.php?filter=word

But I would like to store the value typeAnag=all and composite my url like this: ../index.php?typeAnag=all&filter=word

But when I click the form, I lost the variable value of the previous submit.

I try to use $_SESSION but doesn't work.

Any help would be appreciated

Rastislav Struhár
2#
Rastislav Struhár Reply to 2017-12-06 16:02:06Z

Problem is when u click on second form data in url will be contain just elements from that form not from first form so if u want in second form get information about typeAnag u need to create hidden input in second form....

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304264 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO