core
core copied to clipboard
Validate Existing Email
Hello,
I think this was asked before, but I'm trying to have the form validate if a given email address already exists in the DB, but I can't find where it was. Given there's no community forums anymore, this is my option to ask here.
Thoughts/Directions anyone?
Thanks.
Hey There!
I'd handle this using the Submission Pre-parser module. https://docs.formtools.org/modules/submission_pre_parser/
The general flow would be:
- Take the form submission as it's in flight and check against your form using a database call to validate if the data exists in your form already.
- If the email already exists, write a condition to override the redirect URL and to ignore the submission via the special field values to go back in your form and pass a GET variable or something to notify the user with a message that the email exists. (https://docs.formtools.org/modules/submission_pre_parser/field_values/)
- If the email doesn't exist, then proceed processing as normal.
If you're using Form Tools v3, you can use this as a sample (it's written for Hooks Manager, but the database call is effectively the same). https://gist.github.com/rowright/f7308c07a5486ea5a02447d7573e2558
Hope this helps!