0

Hello, how can I improve this form login with error alerts?
For example, if the fields are empty, if entered data do not match any user, etc. etc.

Right now my form is so, taking advantage of a class:

if(isset($_POST['login'])){

    //Retrieve the field values from our login form.
    $username = !empty($_POST['username']) ? trim($_POST['username']) : null;
    $password = !empty($_POST['password']) ? trim($_POST['password']) : null;

    if($user->login($username, $password)) {
        header('Location: index.php');
    } else {
        $message[] = 'We found problems with the login, please try again.';
    }
}
3
Contributors
2
Replies
17
Views
1 Year
Discussion Span
Last Post by diafol
0

I would suggest you use javascript/jquery to validate data if null etc..
trim the input so no spaces in username and password before validating at javascript

and if all valid send to server.. when data arrives at server check username exists.. if not add error in an array..

and loop through the error array and echo each of them out..

0

JS validation is fine as window dressing, but data validation must also happen on the server. JS validation can be by-passed very easily.

The passing of error info to an array is fine, but you need to be able to access that data in the new page. One way would be to place it in a session variable - and delete it from the session once displayed. Else you could pass an error code in the url:

$_SESSION['form_errors'] = $message;

or

header('Location: index.php?err=64');
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.