Title: Missing trigger?
Last modified: March 28, 2019

---

# Missing trigger?

 *  Resolved [jifola](https://wordpress.org/support/users/jifola/)
 * (@jifola)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/missing-trigger/)
 * Hello,
 * I wanted a function where someone could not submit a duplicate submission, based
   on the IP address of the current user. And the good news is, it works. Almost.
 * You can no longer make the same submission twice, but there seem to be missing
   some kind of trigger. No error messages pops up and the form doesn`t clear. It
   works fine when it is not a duplicate submission.
 * I made a filter that only pulls the submitted existing data based on the IP address
   of the current user. And then check if the current submission is a duplicate.
 * I am missing a invalid trigger of some kind. Any help would be greatly appreciated
   thanks!
 * The code below. It is heavy on the commenting, but I am not a big coder, so I
   need to know exactly what is going on. And maybe others could find it usefull
   🙂
 *     ```
       <?php
   
       // Remember to change url* to what kind of field you are validating. * means it is a required field. Remove the * if it is not.
       add_filter( 'wpcf7_validate_url*', 'my_duplicate_validation', 10, 2 );
       function my_duplicate_validation($result, $tag) {
   
       // Get the existing data
       require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php');
       $exp = new CFDBFormIterator();
       $atts = array();
       $atts['show'] = 'url-submit-input'; // Input name from your form
       $atts['filter'] = 'Submitted From=my_ip_sorting()'; // Custom filter sorting by the current users IP address
       $atts['unbuffered'] = 'true';
       $exp->export($atts['url-submit-form'], $atts); // Name of your form
       $rows = array(); // Make $rows to an array
       while ($row = $exp->nextRow()) {
         $rows[] = $row; // Instead of creating output, just save the data into the array $rows made just before
       }
   
       // Get the current contact form
       $wpcf7 = WPCF7_ContactForm::get_current();
   
       // Get the submission, which is generated when the user hits the submit button
       $submission = WPCF7_Submission::get_instance();
   
       // if a submission is made
       if ($submission) {
   
       // Put the content of the submission into a variable called $posted_data
       $posted_data = $submission->get_posted_data();
   
       // Exit the function if the contact form is empty
       if ( empty ($posted_data))
       return;
   
       // Put the content of a single input into a varible called $tag instead of the whole content from $posted_data
       // You can change the name of $tag, but make sure you change it everywhere
       // The name url-submit-input is the name of a input in my contact form
       $tag = $posted_data['url-submit-input'];
   
       // Check if the value that is submitted is already in the array of values that you pulled from your existing data
       // Url-submit-input is also the name of the field that the data is stored in. Dont confuse it with the name of the input in your form	
       // if(in_array(value to look for, array_column(array to look in, array column to look in)))
       if(in_array($tag, array_column($rows, 'url-submit-input'))) {
   
           // If value submitted in form is found in the data saved in the array $rows. Then it is a duplicate by the current IP address
           // Invalidate and return error
           $result->invalidate($tag, "error" );
   
       } else {
   
       	// If value submitted in form is NOT found in the data saved in the array $rows then it is not a duplicate. Allow the form to send
       	// Remember it is based on the IP address of the current user "$atts['filter'] = 'Submitted From=my_ip_sorting()';"
       	return $result;
   
       } // if in_array end
   
       } // If $submission end
   
       } // Function my_duplicate_validation end
   
       ?>
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fmissing-trigger%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Thread Starter [jifola](https://wordpress.org/support/users/jifola/)
 * (@jifola)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/missing-trigger/#post-11371016)
 * Found a solution that works 🙂 Posted the answer in another thread.
    [https://wordpress.org/support/topic/custom-filter-in-php-and-cf7-custom-validation/#post-11370754](https://wordpress.org/support/topic/custom-filter-in-php-and-cf7-custom-validation/#post-11370754)

Viewing 1 replies (of 1 total)

The topic ‘Missing trigger?’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [error message](https://wordpress.org/support/topic-tag/error-message/)
 * [event](https://wordpress.org/support/topic-tag/event/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [invalidation](https://wordpress.org/support/topic-tag/invalidation/)
 * [trigger](https://wordpress.org/support/topic-tag/trigger/)

 * 1 reply
 * 1 participant
 * Last reply from: [jifola](https://wordpress.org/support/users/jifola/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/missing-trigger/#post-11371016)
 * Status: resolved