One of the additional features I wanted to add on pset7 was to allow the user to reset their password by getting a reset link sent to their e-mail. I want the login page to include a "Forgot Password" link that takes you to a page where you can reset your password.
I followed the example for the register link to try and get it to also go to a "Forgot Password" page by copying pset7/templates/register_form.php
to pset7/templates/forgot_form.php
and pset7/public/register.php
to pset7/public/forgot.php
and changing them to link to the forgot password form:
pset7/templates/forgot_form.php
<form action="forgot.php" method="post">
<fieldset>
Please enter your e-mail address to be sent a password reset link.
<div class="form-group">
<input autofocus class="form-control" name="email" placeholder="E-mail" type="text"/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Send Reset Link</button>
</div>
</fieldset>
</form>
<div>
or <a href="login.php">log in</a>
</div>
pset7/public/forgot.php
<?php
// configuration
require("../includes/config.php");
// if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//TODO: e-mail user link to password reset
}
else {
// else render form
render("forgot_form.php", ["title" => "Forgot Password"]);
}
?>
pset7/templates/login_form.php
<form action="login.php" method="post">
<fieldset>
<div class="form-group">
<input autofocus class="form-control" name="username" placeholder="Username" type="text"/>
</div>
<div class="form-group">
<input class="form-control" name="password" placeholder="Password" type="password"/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Log In</button>
</div>
</fieldset>
</form>
<div>
or <a href="register.php">register</a> for an account
<br>
<br>
<a href="forgot.php"> Forgot Password</a>
</div>
In pset7/templates/login_form.php
, at the bottom I have links to register.php
and forgot.php
. register.php
successfully redirects to the register page, but why does forgot.php
redirect back to the login page?