Home > Blockchain >  PHP get request resets page
PHP get request resets page

Time:12-09

So, I'm making a PHP page. I'm trying to get a url like this

https://nikkiedev.com/folder/indexfile/?schedule-btn=true&time-zone=CET

but instead, when I click on my GET form for the time zone it goes to

https://nikkiedev.com/folder/indexfile/?time-zone=CET

Here's my code:

<div class='mobile-center'>
            <form method="GET">
                <button name="schedule-btn" type="submit" value="true" >schedule</button>
                <button name="roles-btn" type="submit" value="true" >roles</button>
            </form>
            <?php
            $sched_btn = $_GET["schedule-btn"];
            $roles_btn = $_GET["roles-btn"];

            if (isset($sched_btn)) {
                echo "<div class='mobile-center'>";
                echo "<h1>Change schedule</h1>";
                echo "<hr>";
                echo "<p>Choose time zone</p>";
                echo "<form method='GET'>";
                echo "<p>
                <input type='radio' name='time-zone' value='CET'>&nbsp;CET&nbsp;&nbsp;
                <input type='radio' name='time-zone' value='EST'>&nbsp;EST
                <input type='submit'>
                </p>";
                echo "</form>";
                $timezone = $_GET["time-zone"];
                echo "</div>";
                if ($timezone == "CET") {
                    echo "<h1>CET</h1>";
                }
                else if ($timezone == "EST") {
                    echo "<h1>EST</h1>";
                }
            }
            ?>
        </div>

CodePudding user response:

Add the value of $sched_btn as a hidden input in the new form.

           if (isset($sched_btn)) {
                echo "<div class='mobile-center'>";
                echo "<h1>Change schedule</h1>";
                echo "<hr>";
                echo "<p>Choose time zone</p>";
                echo "<form method='GET'>";
                echo "<input type='hidden' name='schedule-btn' value='$sched_btn'>";
                echo "<p>
                <input type='radio' name='time-zone' value='CET'>&nbsp;CET&nbsp;&nbsp;
                <input type='radio' name='time-zone' value='EST'>&nbsp;EST
                <input type='submit'>
                </p>";
                echo "</form>";
                $timezone = $_GET["time-zone"];
                echo "</div>";
                if ($timezone == "CET") {
                    echo "<h1>CET</h1>";
                }
                else if ($timezone == "EST") {
                    echo "<h1>EST</h1>";
                }
            }
  • Related