Created
July 30, 2014 14:53
-
-
Save jpcontrerasv/eac8ac9126878dc01579 to your computer and use it in GitHub Desktop.
Evitar duplicados en contact form 7
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sabe como posso fazer para verificar o mesmo campo em diferentes formulários?