The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Compare new and old field values on form submit
I've made a booking inquiry form on a client's site that includes a date field. I'd like to compare the newly submitted date value to the values in all older entries from the form and send a notification email to the client if the date is a duplicate. I've gotten this to work with CPT postmeta, but Formidable entries seem to work differently. I can't use form validation because I don't want to prevent the form from being submitted
Is there a way to access the entries as a collection of objects (like WP_Query) or arrays?
The Formidable shortcode function "get_form_results" would be perfect if it didn't package the entries in HTML, so if there's a native function/method I've missed, I'll happily use it.
I'd prefer to avoid direct DB queries, but if that's the only way, I'll deal with it. Thanks!
January 5, 2019 at 8:15 am
You can probably do this with Ajax in real time as the date is entered. Or as an alternative, you may be able to query the database before the form is displayed and show the already booked dates as blackout days so they can't be selected at all.
January 5, 2019 at 5:33 pm
Thanks, vfontjr. A clarification though: no date limitations or blackouts are needed on the front end — a person filling out the form can submit whatever date they like (the dates from this form are preliminary, so a duplicate date is not necessarily a conflict). The client who receives the form would just like a notification email if a new inquiry is received for a date that already exists in the database.
I've gotten this idea to work with CPTs for verified bookings — those dates are saved as postmeta so I can collect them those, compare to the newly submitted date, and email as needed using the frm_after_create_entry hook.
I thought about using get_form_results and stripping out the HTML, but that seems backwards to me, since Formidable has to grab the entry values before creating the table.
It sounds like from what you wrote that a wpdb query is required, i.e. there's no available WP_Query equivalent that captures entry data. Is that correct?
January 6, 2019 at 7:35 am
There are quite a few Formidable Hooks available where you can work with data before the entry is created. Entry data is passed to the backend through the global $_POST variable. Take a look at the documentation here: https://formidableforms.com/knowledgebase/
Click on Extend Formidable Forms / Formidable Hooks - for Developers / Entry Management. You may find a hook you can use that will be suitable to your requirement.
Discussion closed.