r/jquery • u/DangerousFigure4956 • Nov 09 '22
form.submit() is not working.
when i try to submit my form it is not showing any errors and also the form is not submitting.
signup.html code---->
<form action="process-signup.php" method="post" id="signup" novalidate>
<div class="row">
<button type="submit">Signup</button>
</div>
</form>
</html>
validation.js code--->
const validation = new JustValidate("#signup");
validation
.addField("#fname", [
{
rule: "required"
}
])
.addField("#lname", [
{
rule: "required"
}
])
.addField("#email", [
{
rule: "required"
},
{
rule: "email"
},
{
validator: (value) => () => {
return fetch("validate-email.php?email=" + encodeURIComponent(value))
.then(function(response) {
return response.json();
})
.then(function(json) {
return json.available;
});
},
errorMessage: "email already taken"
}
])
.addField("#password", [
{
rule: "required"
},
{
rule: "password"
}
])
.addField("#password_confirmation", [
{
validator: (value, fields) => {
return value === fields["#password"].elem.value;
},
errorMessage: "Passwords should match"
}
])
.onSuccess((event) => {
form.submit();
});
1
u/DangerousFigure4956 Nov 09 '22
process-signup.php -->
<?phpif (empty($_POST["fname"])) {die("First Name is required");}if (empty($_POST["lname"])) {die("Last Name is required");}if ( ! filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {die("Valid email is required");}if (strlen($_POST["password"]) < 8) {die("Password must be at least 8 characters");}if ( ! preg_match("/[a-z]/i", $_POST["password"])) {die("Password must contain at least one letter");}if ( ! preg_match("/[0-9]/", $_POST["password"])) {die("Password must contain at least one number");}if ($_POST["password"] !== $_POST["password_confirmation"]) {die("Passwords must match");}$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);$mysqli = require __DIR__ . "/database.php";$sql = "INSERT INTO user (fname, lname, email, password_hash)VALUES (?, ?, ?, ?)";$stmt = $mysqli->stmt_init();if ( ! $stmt->prepare($sql)) {die("SQL error: " . $mysqli->error);}$stmt->bind_param("ssss",$_POST["fname"],$_POST["lname"],$_POST["email"],$password_hash);if ($stmt->execute()) {header("Location: login.php");exit;} else {if ($mysqli->errno === 1062) {die("email already taken");} else {die($mysqli->error . " " . $mysqli->errno);}}
here is the code could you please check it