-
-
Save Lonsdale201/d4fe08ff14bf22999220f78e9c5164c1 to your computer and use it in GitHub Desktop.
Elementor Form - Fluent CRM Contact validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This code checks if the visitor's email address is already in your fluentCRM database as a contact | |
| // based on the target email field, if it is, it will give you feedback and the submission will not run. | |
| // place the code in the child theme functions.php or a custom code snippets plugin, like FluentSnippets | |
| // Change the $email_field_id = 'email'; email with your field id | |
| // You need to set a name for your form: if ($form_name !== 'FluentForm') { | |
| // HELP IMAGE https://prnt.sc/5rsOUX84ALYX | |
| // HELP IMAGE: https://prnt.sc/a1FIhRDVZ9tA | |
| // Change this: $ajax_handler->add_error($email_field['id'], 'This email address is already registered in our CRM system.'); | |
| add_action('elementor_pro/forms/validation', function($record, $ajax_handler) { | |
| // Only run this for forms with the name "FluentForm" | |
| $form_name = $record->get_form_settings('form_name'); | |
| if ($form_name !== 'FluentForm') { | |
| return; | |
| } | |
| // Change this to your actual email field ID | |
| $email_field_id = 'email'; | |
| $fields = $record->get('fields'); | |
| $email_field = null; | |
| foreach ($fields as $field) { | |
| if ($field['id'] === $email_field_id) { | |
| $email_field = $field; | |
| break; | |
| } | |
| } | |
| if (!$email_field) { | |
| return; | |
| } | |
| $email = $email_field['value']; | |
| $contactApi = FluentCrmApi('contacts'); | |
| $contact = $contactApi->getContact($email); | |
| if ($contact) { | |
| $ajax_handler->add_error($email_field['id'], 'This email address is already registered in our system.'); | |
| } | |
| }, 10, 2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment