- This topic is empty.
-
AuthorPosts
-
March 14, 2017 at 12:24 am #252744MineshRaiParticipant
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
March 14, 2017 at 2:21 am #252745BeverleyhParticipantAssuming 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.
March 14, 2017 at 6:54 am #252753MineshRaiParticipantHi Beverleyh,
Thanks for ur answer.I am using WordPress. Is this code will work on WordPress.
Plz tell.
March 14, 2017 at 8:32 am #252763BeverleyhParticipantI have no idea – I’m not that familiar with WordPress. Sorry.
-
AuthorPosts
- The forum ‘Other’ is closed to new topics and replies.