Support » Plugin: Contact Form DB » preventing duplicate submission code error

  • Hello everyone, ideas and help needed!

    I want to prevent duplicate email submissions to the CF7. So I followed instructions from https://cfdbplugin.com/?page_id=904 but get an error when entering any email to the CF7 form:

    Shortcodes, Actions and Filters Plugin: Error in user-provided code item named “Preventing Duplicate Submissions from CF7 2”.
    syntax error, unexpected ‘$fieldName’ (T_VARIABLE)

    My code is:

    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”;
    $atts[‘unbuffered’] = ‘true’;
    $exp->export($formName, $atts);
    $found = false;
    while ($row = $exp->nextRow()) {
    $found = true;
    }
    return $found;
    }
    function my_validate_email($result, $tag) {
    $formName = ‘cf7form’; // Change to name of the form containing this field
    $fieldName = ‘emailfield’; // Change to your form’s unique field name
    $errorMessage = ‘ERROR MESSAGE HERE’; // Change to your error message
    $name = $tag[‘name’];
    if ($name == $fieldName) {
    if (is_already_submitted($formName, $fieldName, $_POST[$name])) {
    $result->invalidate($tag, $errorMessage);
    }
    }
    return $result;
    }
    add_filter(‘wpcf7_validate_email*’, ‘my_validate_email’, 10, 2);

    any ideas what’s wrong?
    Thank you!

  • You must be logged in to reply to this topic.