Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jpcontrerasv/eac8ac9126878dc01579 to your computer and use it in GitHub Desktop.
Save jpcontrerasv/eac8ac9126878dc01579 to your computer and use it in GitHub Desktop.
Evitar duplicados en contact form 7
1 -
Change $formName to the name of your form
Change $fieldName to the name of your email field
Optionally change the error message
2- (agregar al functions.php)
function is_already_submitted($formName, $fieldName, $fieldValue){
require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
$exp = new CFDBFormIterator();
$atts = array();
$atts['show'] = $fieldName;
$atts['filter'] = "$fieldName=$fieldValue";
$exp->export($formName, $atts);
$found = false;
while ($row = $exp->nextRow()) {
$found = true;
}
return $found;
}
function my_validate_email($result, $tag) {
$formName = 'email_form'; // Name of the form containing this field
$fieldName = 'email_123'; // Set to your form's unique field name
$name = $tag['name'];
if($name == $fieldName){
$valueToValidate = $_POST[$name];
if (is_already_submitted($formName, $fieldName, $valueToValidate)) {
$result['valid'] = false;
$result['reason'][$name] = 'Email has already been submitted'; // error message
}
}
return $result;
}
add_filter('wpcf7_validate_email*', 'my_validate_email', 10, 2);
@miguel220978
Copy link

no me funciona

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment