jpcontrerasv
7/30/2014 - 2:53 PM

Evitar duplicados en contact form 7

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);