Page 1 of 1

Login Form

Posted: Mon Jul 19, 2010 10:25 am
by christh
Hi

Can somebody help with the mechanics/thought process behind a login form? I can do all the form creation and user checking but I'm struggling with performing the validation on the same page as the form and then moving to a new page once all is good - apologies should this not make sense but I'm struggling to explain it even to myself. The code below may help.

Code: Select all

if(isset($_POST['submit'])) 
{ 
1.Connect and check the input against the records stored.
2.If everything is good, return to the page that called for the login
3. If it's not good return to the form
}

}

?>

<HTML>
<title><title>Login</title></HEAD>
<BODY>
<FORM method="post" action="<?php echo $PHP_SELF;?>">
	<label for ="login" >Login</label>
   	<input type="text" name="login" style="font-size:10px;" value="your email address">
	<label for ="password" >Password</label>
	<input type="password" name="password" style="font-size:10px;">
<input type="submit" name="submit" value="Login">
</FORM>
If I use the PHP_Self reference, how do I then move away from the form once everything is ok? Or if I set the from action to go to the page I want to ultimately go to how to I validate the information before going and stay if it's wrong?

Again sorry for the confusing content above but I'm not sure how best to explain.

Thanks

Chris

Re: Login Form

Posted: Mon Jul 19, 2010 10:51 am
by JayBird

Code: Select all

if(isset($_POST['submit'])) 
{ 
$data = $_POST;

if(!empty($data['emailAddress'] )&& !empty($data['password']))
}
header("Location: /path/to/your/next/page");
}

?>

<HTML>
<title><title>Login</title></HEAD>
<BODY>
<FORM method="post" action="<?php echo $PHP_SELF;?>">
	<label for ="login" >Login</label>
   	<input type="text" name="login" style="font-size:10px;" value="your email address" value="<?php echo $data['emailAddress']; ?>>
	<label for ="password" >Password</label>
	<input type="password" name="password" style="font-size:10px;" value="<?php echo $data['password']; ?>>
<input type="submit" name="submit" value="Login">
</FORM>

Re: Login Form

Posted: Mon Jul 19, 2010 5:50 pm
by christh
Jaybird

Many thanks for your help.

Didn't know about header("Location: /path/to/your/next/page"); which is really handy.

Thanks again.

Chris