Created
June 23, 2020 09:55
-
-
Save ThemeCatcher/d2934b3a4aa22d120ad1992ef1dff479 to your computer and use it in GitHub Desktop.
Validate that value exists in the entries for another form
This file contains 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
add_filter('quform_element_valid_2_4', function ($valid, $value, Quform_Element_Field $element) { | |
if ($element->getForm()->config('environment') != 'frontend') { | |
return $valid; | |
} | |
global $wpdb; | |
$repository = quform('repository'); | |
$emailElementId = '1_3'; | |
list($formId, $elementId) = explode('_', $emailElementId); | |
$query = "SELECT `e`.`id` FROM `" . $repository->getEntryDataTableName() . "` ed LEFT JOIN `" . | |
$repository->getEntriesTableName() . "` e ON `ed`.`entry_id` = `e`.`id` | |
WHERE `e`.`form_id` = %d | |
AND `ed`.`element_id` = %d | |
AND `ed`.`value` = %s"; | |
$args = array( | |
$formId, | |
$elementId, | |
$value | |
); | |
$result = $wpdb->get_row($wpdb->prepare($query, $args)); | |
if ($result == null) { | |
$element->addError('Email address not found'); | |
$valid = false; | |
} | |
return $valid; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code can be added to the WP theme functions.php file or using a plugin like My Custom Functions.
2_4
with the unique ID of the field you want to validate1_3
with the unique ID of the field to search the entries for