• Resolved jolive

    (@jolive)


    I run a children’s sports team and I use contact form to help with registration for events. I want to prevent duplicates but I need to filter on 2 or 3 fields. Like “First Name” AND “Last Name” AND “Email address”. Some families have more than one child so just checking against last name or email address may prevent them from signing up a second kid. Any thoughts?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author wpnia

    (@wpnia)

    Hello jolive,

    This plugin does not treat this case.

    So, to achive what you desire you need to edit source code of this plugin.

    • For that you need to go to your WordPress administrator page->Plugins->Plugin File Editor
    • From the right side -> Select plugin to edit -> search for Duplicate Killer
    • From Plugin files search for ‘functions_cf7.php’ file under ‘includes’ folder
    • You need to replace the entire function duplicateKiller_cf7_before_send_email from line 48 to 127.
      Replace with:
    function duplicateKiller_cf7_before_send_email($contact_form, &$abort, $object) {
        global $wpdb;
        $table_name = $wpdb->prefix.'dk_forms_duplicate';
    	$cf7_page = get_option("CF7_page");
        $submission = WPCF7_Submission::get_instance();
    	$form_name = $contact_form->title();
    	$form_cookie = isset($_COOKIE['dk_form_cookie'])? $form_cookie=$_COOKIE['dk_form_cookie']: $form_cookie='NULL';
        if($submission){
    		$abort = false;
    		$no_form = false;
    		$AND = array();
            $data = $submission->get_posted_data();
            $form_data = array();
            foreach ($data as $key => $d) {
                $tmpD = $d;
    				if (!is_array($d)){
    					$bl   = array('\"',"\'",'/','\\','"',"'");
    					$wl   = array('"',''','/', '\','"',''');
                        $tmpD = str_replace($bl, $wl, $tmpD );
                    }
                    //$form_data[$key] = $tmpD;
    				foreach($cf7_page as $cf7_form => $cf7_tag){
    					if($form_name == $cf7_form){
    						$i = count($cf7_tag);
    						if(array_key_exists($key,$cf7_tag)){
    							$no_form = true;
    							if($result = duplicateKiller_check_duplicate("CF7",$form_name)){
    								foreach($result as $row){
    									$form_value = unserialize($row->form_value);
    									if(isset($form_value[$key]) AND duplicateKiller_check_values_with_lowercase_filter($form_value[$key],$tmpD)){
    										$AND[$key] = $form_value[$key];
    										//echo $j.' '.$form_value[$key].'</br>'; 
    										if(function_exists('cfdb7_before_send_mail')){
    											remove_action('wpcf7_before_send_mail', 'cfdb7_before_send_mail');
    										}
    										$cookies_setup = [
    											'plugin_name' => "cf7_cookie_option",
    											'get_option' => $cf7_page,
    											'cookie_stored' => $form_cookie,
    											'cookie_db_set' => $row->form_cookie
    										];
    										
    									}else{
    										if(!empty($tmpD))
    										$form_data[$key] = $tmpD;
    									}
    								}
    							}else{
    								if(!empty($tmpD))
    								$form_data[$key] = $tmpD;
    							}
    						}
    					}
    				}
            }
    		
    		//print_r($AND);
    		if($i==count($AND)){
    			if(dk_check_cookie($cookies_setup)){
    					$abort = true;
    					$object->set_response($cf7_page['cf7_error_message']);						
    			}
    			
    		}
    		//echo $i.' '.$j;
    		//exit();
    		if(!$abort AND $no_form){
    			$form_value = serialize($form_data);
    			$wpdb->insert(
    			$table_name,
    			array(
    				'form_plugin' => "CF7",
    				'form_name' => $form_name,
    				'form_value'   => $form_value,
    				'form_cookie' => $form_cookie
    			) 
    		);
    		}
        }
    }

    NOTE: This code is for Contact Form 7, it wasn’t tested with other form plugins!
    Also, please test it rigorous before going live!

    Let me know if you have any question.

    Thank you,
    NIA

    Plugin Author wpnia

    (@wpnia)

    Let me know if you have any question.

    Topic closed!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘“AND” Between fields’ is closed to new replies.