Check a list of emails for values not in database

By: Jane Onorati | Asked: 01/24/2023
ForumsCategory: Code HelpCheck a list of emails for values not in database
Jane OnoratiJane Onorati asked 1 year ago
I would like to have a way someone can check a list of emails from the front end to see if any are not found in the database.  Not really sure if or how this could be done.  The list would come from a csv file and have anywhere from 20 to 120 emails in it.  I need some ideas on where to start. I think I can figure out the sql query part but don't know how a list can be inputted so a query can be run on it, and results can be returned.  Might it work to copy and paste in the list of emails into a form paragraph or rich text box?  Or upload a text or csv file?  Then what? -Jane
3 Answers
Victor Font answered 1 year ago
What you want to do requires a custom solution. Neither WordPress nor Formidable has the functionality to to what you want out of the box. You could use a Formidable upload field to upload the CSV file, then process it in a Formidable hook or with Ajax. Either way can return a result. The SQL and list processing is all custom.
Jane OnoratiJane Onorati answered 1 year ago
Thanks Victor.  I figured that much.  Do you have any examples using the hook needed to get me started?  I think I can figure out how to parse the file and query the database for each email in it but don't know how to access it.
Victor Font replied 1 year ago

You might be best off using one of the hooks that fire either before or after entry creation. You can possible also trigger a result with the Ajax.complete() event from the upload. I haven't researched this, but the kind of custom code you need to write may not be able to use any available WordPress or Formidable functions. Formidable has functions for CSVs but I'm not sure how helpful they'll be. You may have to resort to PHP low-level file handing functions to open, parse, and process your email addresses. You're breaking new ground.

Jane OnoratiJane Onorati answered 9 months ago

I figured out a solution to this.  I created a form that has two paragraph fields in it and wrote a php script that uses the 'frm_pre_create_entry' filter.

  1. The user is instructed to copy and paste a column of email addresses from a spreadsheet or other document into the paragraph field and then click the Submit button.
  2. The script creates an array of the provided emails, and also creates a second array from a database query for emails in another form to compare with. Then the array_diff() function is used to find emails in first array that are not in second array, and the result is used to update another paragraph field that is hidden (since the result will not be available until after the form is submitted).
  3. The form is set to redirect to a page with a view for this form that shows only the result for the most recent entry.

^^ -Jane 

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community