Stop form from sending when validation fails.
I have an internal validation for the input field on my form and I don't wanţthe form to submit when the user has an invalid email address based on my requirements. I have tried e.preventDefault() and return false; but it is still not working😭😭. I need help it is super urgent.
This is what my input validation looks like
this is what my submit to google sheet api looks like.
PLEASE what am i doing wrong?
2 Replies
You're not doing any validation before sending the fetch request. Your code doesn't check if the email is correct before sending the form.
What you should be doing, right after
e.prevenDefault()
is checking the email validity. If not valid, do an early return:
This hooks into your valid()
function that is adding/removing the active
class from the email input element.It worked
Honestly, I didn't know what i was thinking😭😭 You are amazing.. Thank you so much
It worked
You are amazing