jQuery:
$("#register-form").submit(function(event) {
event.preventDefault();
$.post("./register.php", {
username: $("#username").val(),
password: $("#password").val(),
passwordtwo: $("#passwordtwo").val(),
email: $("#email").val()
},
function(response) {
$("#errors").html(response);
$("#errors").slideDown("slow");
});
});
This works perfectly and displays the errors I return. But if the form passes all the checks I get a problem.
if ($error) {
echo $error; // returns errors in form
} else {
// Password Hash & Salt functions are here
// sets a cookie to log them in here
header("Location: " . getenv("HTTP_REFERER")); // the problem
}
Because of my current jQuery function, the response will return the HTTP_REFERER so it loads the who previous page inside the <div id="errors"></div> I have.
Is there some kind of success parameter or some way to do something else if it passes all the checks?
Use JSON on PHP part,
And modify Javascript to handle the json.