Support » Plugin: Contact Form DB » preventing duplicate submissions from cf7

  • Hi,

    I have a form where user add his email address, I’m trying to prevent users to enter there email many times. I used your plugin to save email address and export them to excel. while searching on internet I found this solution (link below) but I can’t get it work can you help me please :

    https://cfdbplugin.com/?page_id=904

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi
    Install the plugin Shortcodes, Actions and Filters. Add a new function and add this in the code editor:

    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 = 'NAME OF YOUR FORM'; // Change to name of the form containing this field
        $fieldName = 'NAME OF YOUR E-MAIL FIELD'; // 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);

    Remove the * from the bottom line if the field is NOT a required field. Otherwise leave it. This works for me, that’s all I can say.

    Plugin Author Michael Simpson

    (@msimpson)

    Change these three lines in the above code to match your need:

    
        $formName = 'NAME OF YOUR FORM'; // Change to name of the form containing this field
        $fieldName = 'NAME OF YOUR E-MAIL FIELD'; // Change to your form's unique field name
        $errorMessage = 'ERROR MESSAGE HERE'; // Change to your error message
    

    Hi About preventing also the submission of same like example I have an inout collecting web urls and if they submit http://www.sample.com.au 2 times it will not goes through same if you enter http://www.sample.com.au/url like same like..is that possible?

    Hi,

    I have followed the instruction in the tutorial (https://cfdbplugin.com/?page_id=904) to prevent duplicate submission based on email address. Everything works fine except that the error message is not showing properly, i.e., the desired message is not shown and instead the default message is being displayed. Somehow the error message is ovderwritten by the default one! I really appreciate it if you could help me.

    Best Regards
    Nima

    Hmm
    it seems that this code is blocking an email entry forever. I would like an option to block submitting the same entry for 5 – 10 minutes.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘preventing duplicate submissions from cf7’ is closed to new replies.