i have a login form. if there is a error. let say user doesnt fill input fields. than it will print error. but i want to keep the values safe. that way user dont have to keep fill in data again and again.
here i have a form. iam print the error. and than there are some input fields.
in side that
if(array_key_exists('log_error', $_SESSION) && !empty($_SESSION['log_error']))
i want to set user data back to fields.
<form id='login' action='login.php' method='POST'>
<?php
//print errors
if(array_key_exists('log_error', $_SESSION) && !empty($_SESSION['log_error']))
{
$log_error_r = $_SESSION['log_error'];
echo "<span style='background-color:#D00000;'> $log_error_r <br/></span>";
unset($_SESSION['log_error']);
}
?>
<input type="text" name="username" id="login_username" class="login_field" value="" />
<input type="password" name="password" id="login_password" class="login_field" value=""/>
<input type="checkbox" name="remember" id="login_remember" value="yes" />
<button type="submit">Log in</button>
</form>
php file
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$username_p = $_POST['username'];
$password_p = $_POST['password'];
$log_error = "";
echo"$password_p";
if($username_p && $password_p)
{
if(strlen($username_p) > 20 && strlen($password_p) > 20)
{
$log_error .= "Error - Username or Password too long!";
}
else
{
.....
$_SESSION['log_error'] = $log_error;
}
?>