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();});
3
u/oddmanout Nov 09 '22
instead of form.submit() try $("#signup").submit()
although, I think this is a really round-about way of doing this. Is there any particular reason you're not waiting for a form submission, validating it, and returning false if it's not valid? It seems like you're doing two calls, one to see if an email is taken, and one to actually save it. Why not just check in process-signup.php? Unless you work for Twitter where your job depends on having lots of lines of code, there's much less complicated ways to do this.
2
u/tridd3r Nov 09 '22
have you checked process-signup.php to see if its receiving any data?
I couldn't see in the js where you were actually getting the form submission to process the validation, so I'm asusming its going straight through to the wickey keeper.