kringshot Posted May 28, 2009 Share Posted May 28, 2009 I have a form that currently sends the data entered (username/password) back to the same page as such: <form class="login" action="" method="post"> This is so I can validate login at the top of the page etc. Now what I want it to also do is to post the data to the next page AS WELL, as I want to be able to use the username on the next page (Welcome $user!) (well, more complicated than this but you get the idea) Is this possible at all? Quote Link to comment https://forums.phpfreaks.com/topic/159974-solved-is-it-possible-for-1-form-to-have-2-actions/ Share on other sites More sharing options...
KevinM1 Posted May 28, 2009 Share Posted May 28, 2009 I have a form that currently sends the data entered (username/password) back to the same page as such: <form class="login" action="" method="post"> This is so I can validate login at the top of the page etc. Now what I want it to also do is to post the data to the next page AS WELL, as I want to be able to use the username on the next page (Welcome $user!) (well, more complicated than this but you get the idea) Is this possible at all? Not without using JavaScript. Thankfully, what you want to do is rather simple to execute using sessions. Google 'PHP sessions' to get started. Quote Link to comment https://forums.phpfreaks.com/topic/159974-solved-is-it-possible-for-1-form-to-have-2-actions/#findComment-843810 Share on other sites More sharing options...
.josh Posted May 28, 2009 Share Posted May 28, 2009 so what's the point in sending the data to some validation script if you want to at the same time send it straight to some other page to be used? Send the data to your validation script. Validate it. Put it in a session var as Night suggested. Redirect to new page. And they lived happily ever after. The end. Quote Link to comment https://forums.phpfreaks.com/topic/159974-solved-is-it-possible-for-1-form-to-have-2-actions/#findComment-843819 Share on other sites More sharing options...
kringshot Posted May 28, 2009 Author Share Posted May 28, 2009 Hmm I'm pretty sure thats what I am doing, I just can't seem to get it out of the session. Starting to think I might be stupid! (please dont answer that hah) Right, top of login.php checks to see if it's there and then uses the posted data in $pupils validate_user function. if($_POST && !empty($_POST['username']) && !empty($_POST['password'])) { $response = $pupils->validate_user($_POST['username'], $_POST['password']); and the validate_user function from pupils.php function validate_user($user,$pass){ $mysql = new connect(); $ensure_credentials = $mysql->verify_user_pass($user, $pass); //If ensure_credentials holds true then status is authorised and user is sent to the index page if($ensure_credentials){ $_SESSION['status'] = 'authorised'; header("location: index.php"); } else return "Please enter a correct username and/or password!"; } Now the log in works and the athentication works, but what would I type on another page (say images.php) to use just the username from this session? Quote Link to comment https://forums.phpfreaks.com/topic/159974-solved-is-it-possible-for-1-form-to-have-2-actions/#findComment-843832 Share on other sites More sharing options...
.josh Posted May 28, 2009 Share Posted May 28, 2009 if($ensure_credentials){ $_SESSION['status'] = 'authorised'; $_SESSION['user'] = $user; header("location: index.php"); } else return "Please enter a correct username and/or password!"; index.php <?php session_start(); echo $_SESSION['user']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/159974-solved-is-it-possible-for-1-form-to-have-2-actions/#findComment-843838 Share on other sites More sharing options...
kringshot Posted May 28, 2009 Author Share Posted May 28, 2009 Genious! Nice one mate, my work can continue. Quote Link to comment https://forums.phpfreaks.com/topic/159974-solved-is-it-possible-for-1-form-to-have-2-actions/#findComment-843844 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.