• Resolved nonchiedercilaparola

    (@nonchiedercilaparola)


    hi, i need an help to get exportable record db without email field duplication in other words if i export cvs cfdb thera won’t be row with two identical field email.

    solution 1) filter the export/listed row in a way that duplicate field mail aren’t present;

    solution 2) after a successful user success submission we check if the field email exsist into the db and save only in the case that the field email isn’t exsist.

    regards

    https://www.ads-software.com/plugins/contact-form-7-to-database-extension/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    1: you would have to write a transform to add to your shortcode or
    Export to remove duplicates:
    https://cfdbplugin.com/?page_id=1095

    2: a solution is provided when using CF7 forms:
    https://cfdbplugin.com/?page_id=904

    Thread Starter nonchiedercilaparola

    (@nonchiedercilaparola)

    hi, i use contact form 7 but i want that that a user can use the form more times. i would like to prevent cfdb to save a submission if the email field is exsist.

    Plugin Author Michael Simpson

    (@msimpson)

    Thread Starter nonchiedercilaparola

    (@nonchiedercilaparola)

    sorry for my bad explanation. i don’t want prevent duplicate submission of a user but i don’t want row-record into the cfdb with two identical email field.

    a user with [email protected] use my form –> i get this mail –> cfdb update the db with new row-record
    same user with same email ( [email protected] ) use my form again –> i get this mail –> cfdb not update the db with new row-record.

    with https://cfdbplugin.com/?page_id=904 we “… don’t want them to submit more than once.” but i want that same user with same email can use my contact form to send me email.

    “submit” to me means that the email generated from my form is send to me.

    “is_already_submitted” ? yes, don’t save into db but send the email

    ca i use this contact form 7 hook? do_action_ref_array( ‘wpcf7_before_send_mail’, array( &$data) );

    Plugin Author Michael Simpson

    (@msimpson)

    I think you are saying that when a second submission is done with a duplicate email, then you want form submission to succeed but CFDB should not save it.

    Referring to: https://cfdbplugin.com/?page_id=747

    In your case, you want to return null from the filter and it will prevent saving.

    function dont_save_if_duplicate_email($formData){
        $formName = 'dateform'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            // Add code in here to check for duplicate email
            // Reference: https://cfdbplugin.com/?page_id=904
            $duplicate = true;
            if ($duplicate) {
                return null; // stops CFDB from saving
            }
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'dont_save_if_duplicate_email');

    Thread Starter nonchiedercilaparola

    (@nonchiedercilaparola)

    i try this code:

    /**
     * @param $formName string
     * @param $fieldName string
     * @param $fieldValue string
     * @return bool
     */
    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 dont_save_if_duplicate_email($formData){
        $formName = 'Home Contact Form'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            // Add code in here to check for duplicate email
            $fieldName = 'email-773';
            $name = $formData->posted_data['email-773']['name'];
            if ($name == $fieldName) {
                if (is_already_submitted($formName, $fieldName, $_POST[$name])) {
                	$duplicate = true;
            	}
            }
            if ($duplicate) {
                return null; // stops CFDB from saving
            }
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'dont_save_if_duplicate_email');

    but in this way ajax loader don’t stop and the cfdb don’t prevent to save the submission.

    “JSON.parse: unexpected keyword at line 1 column 1 of the JSON data”
    i insert this to my functions.php

    Plugin Author Michael Simpson

    (@msimpson)

    I suggest to start with the following to make sure it is being called and submissions are not being saved, then add some more code & check, add some more & check…

    function dont_save_if_duplicate_email($formData){
        return null; // stops CFDB from saving
    }
    add_filter('cfdb_form_data', 'dont_save_if_duplicate_email');
    Thread Starter nonchiedercilaparola

    (@nonchiedercilaparola)

    now the ajax loader not stop when the email address is new:( the probllem is “return $formData;” this generate the problem.

    /**
     * @param $formName string
     * @param $fieldName string
     * @param $fieldValue string
     * @return bool
     */
    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 dont_save_if_duplicate_email($formData){
        $formName = 'Home Contact Form'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            // Add code in here to check for duplicate email
            $fieldName = 'email-773';
            $name = $formData->posted_data['email-773'];
                if (is_already_submitted($formName, $fieldName, $name)) {
                	$duplicate = true;
                }
            if ($duplicate) {
                return null; // stops CFDB from saving
            }
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'dont_save_if_duplicate_email');

    Great think is the possibility to:

    merge rows from multiple forms and then automatically save the list in an external

    Thread Starter nonchiedercilaparola

    (@nonchiedercilaparola)

    This finally works:

    /**
     * @param $formName string
     * @param $fieldName string
     * @param $fieldValue string
     * @return bool
     */
    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 dont_save_if_duplicate_email($formData){
        $formName = 'Home Contact Form'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            // Add code in here to check for duplicate email
            $fieldName = 'email-773';
            $name = $formData->posted_data['email-773'];
                if (is_already_submitted($formName, $fieldName, $name)) {
                	$duplicate = true;
                } else {
                	$duplicate = false;
                }
            if ($duplicate) {
                return null; // stops CFDB from saving
            }
            return $formData;
    
        }
    }
    
    add_filter('cfdb_form_data', 'dont_save_if_duplicate_email');
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘is it a way to don't save/export row with exisinting field email?’ is closed to new replies.