Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to display Form values after login on another page

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #252744
    MineshRai
    Participant

    Hi,

    I have created a bootstrap form with an input field and a button. I want to display Form values after login on another page. I have added following codes:

    Page 1

    <form method=”POST” action=”test.php”>

    <label for=”reward”>Reward</label>
    <input type=”number” class=”form-control” name=”reward” min=”1″ aria-label=”Amount (to the nearest dollar)” placeholder=”Amount” required>

    <button type=”submit” class=”btn btn-success”>Continue</button>
    </form>

    Page 2 (test.php)

    <?php
    if(isset($_POST[‘reward’])) {
    echo $_POST[‘reward’];
    }
    ?>

    With the above codes I am getting the the form values displayed on another page. But I want to add a login process in between.

    Means, If on Page 1, a person entered a “desired amount” in form field and click the button. He should be prompted for login/register. After completing the process of Login/Register he should be redirected to Page 2 and Page two should display the “desired amount”.

    How to do Plz help.

    Thanks

    #252745
    Beverleyh
    Participant

    Assuming that you’re working with PHP sessions, and that you already have a login script that generates a session, you would put this line at the very top of test.php (and any other page where you need to identify sessions)
    “`
    session_start();
    “`

    Then, let’s assume that the session name set by your login script is ‘username’, your test.php file could include this sort of logic;
    “`
    if(isset($_POST[‘reward’])) {
    $reward = $_POST[‘reward’];
    } else {
    $reward = ”;
    }

    if($_SESSION[‘username’]) { // if logged in
    echo $reward;
    } else { // if not logged in
    // stuff for login form and register button
    $_SESSION[‘reward’] = $reward; // create session for reward value
    }
    “`

    And then on the login/register page, you should be able to continue accessing the $reward value via the session, like this;
    “`
    $reward = $_SESSION[‘reward’];
    “`

    This is just rough logic though, so for a better understanding you should research/study a few tutorials on using sessions in PHP.

    Good luck with your project.

    #252753
    MineshRai
    Participant

    Hi Beverleyh,
    Thanks for ur answer.

    I am using WordPress. Is this code will work on WordPress.

    Plz tell.

    #252763
    Beverleyh
    Participant

    I have no idea – I’m not that familiar with WordPress. Sorry.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Other’ is closed to new topics and replies.