Password confirmation issue

Joined
Aug 16, 2022
Messages
52
Reaction score
2
Hi Everybody,

I have a form that will ask a visitor to make a password, and then re-enter the same password to confirm. The HTML code is as follows:
HTML:
<div class="row">
    <div class="col-sm-6 form-group">
        <div class="input-group">
            <span class="input-group-text"><i class="bi-key-fill" arial-hidden="true"></i>&nbsp;</span>
            <input type="password" class="form-control" placeholder="Your Password" id="PW1" name="PW1" required="required">
        </div>
    </div>
    <div class="col-sm-6 form-group">
        <div class="input-group">
            <span class="input-group-text"><i class="bi-key-fill" arial-hidden="true"></i>&nbsp;</span>
            <input type="password" class="form-control" placeholder="Enter Password Again to confirm" id="PW2" name="PW2" required="required"><br>
        </div>
    </div>
</div>
And it will look like this.
Screenshot 2023-09-20 132406.png

I plan to evaluate both inputs with this:

PHP:
if ($_POST["PW1"]) !== $_POST["PW2"] {

} else {
        ????????
}

My issue is if the evaluation fails, I want to clear the two responses and start the process again.

How on earth will I do that?




:::::
 

Attachments

  • Screenshot 2023-09-20 131041.png
    Screenshot 2023-09-20 131041.png
    3.4 KB · Views: 5
Joined
Nov 13, 2020
Messages
302
Reaction score
38
A simple answer, but first some logic. When I was a young fledgling tadpole my froggy father said, "Never send things to the server that will come back, test them with JavaScript (the savior of extra web traffic) first before you send them the first time.".
So test with JS and do the DOM thing before asking PHP to do it. And of course, also test in PHP.
 
Joined
Aug 16, 2022
Messages
52
Reaction score
2
Thanks BigDady,

But how would I clear the two responces, and start the process over again at : <div class="row">
 
Joined
Jul 4, 2023
Messages
366
Reaction score
41
Did you tried something like that?
PHP:
<?php
    $passwords_equality = '';

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $pw1 = $_POST["PW1"] ?? null;
        $pw2 = $_POST["PW2"] ?? null;
        if ($pw1 && ($pw1 == $pw2)) {
            // Do something when passwords are equal
            // check some data from database
            // set some session variables
            // redirect the call to another page ect.
        } else {
            $passwords_equality = 'Passwords do not match!';
        }
    }
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>

        <style>
            .error {
                color: red;
                padding: .5rem 1rem;
            }
        </style>
    </head>
    <body>
        <form method="post">
            <div class="row">
                <div class="col-sm-6 form-group">
                    <div class="input-group">
                        <span class="input-group-text"><i class="bi-key-fill" arial-hidden="true"></i>&nbsp;</span>
                        <input type="password" class="form-control" placeholder="Your Password" id="PW1" name="PW1" required="required">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6 form-group">
                    <div class="input-group">
                        <span class="input-group-text"><i class="bi-key-fill" arial-hidden="true"></i>&nbsp;</span>
                        <input type="password" class="form-control" placeholder="Enter Password Again to confirm" id="PW2" name="PW2" required="required"><br>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6 form-group">
                    <span class="error"><?php echo $passwords_equality; ?></span>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6 form-group">
                    <button type="submit" class="form-control">Submit</button>
                </div>
            </div>
        </form>
    </body>
</html>
 
Joined
Aug 16, 2022
Messages
52
Reaction score
2
Thanks Fellows.

BigDady was right! I shouldn't be using PHP to validate the two inputs. I'll move over to the JavaScript forum to ask about it.
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
jPaulB, You also MUST re-evaluate using PHP. This is important to do anytime the user sends you anything.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top