unique emails contact form 7 code example
Example: unique emails contact form 7
function is_already_submitted($formPostId, $fieldName, $fieldValue) {
global $wpdb;
$entry = $wpdb->get_results( "SELECT * FROM DB_PREFIX_db7_forms WHERE form_value LIKE '%$fieldValue%' AND form_post_id = '$formPostId'" );
$found = false;
if (!empty($entry)) {
$found = true;
}
return $found;
}
function my_validate_email($result, $tag) {
$formPostId = 'FORM_ID';
$fieldName = 'your-email';
$errorMessage = 'This email address is already registered';
$name = $tag['name'];
if ($name == $fieldName) {
if (is_already_submitted($formPostId, $fieldName, $_POST[$name])) {
$result->invalidate($tag, $errorMessage);
}
}
return $result;
}
add_filter('wpcf7_validate_email*', 'my_validate_email', 10, 2);