formtools / core

The Form Tools Core.
https://formtools.org
207 stars 78 forks source link

Validate Existing Email #753

Open ocbroadband opened 3 years ago

ocbroadband commented 3 years ago

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.

ghost commented 3 years ago

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:

  1. 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.
  2. 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/)
  3. 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!