• Hello,

    Great plugin !
    Working perfect on a page using the shortcode [cfdb-save-form-post]
    used with my own form (meaning not using any plugin form; I did create my own plugin and put my own shortcode to be displayed within a specific page).

    i did use a filter to verify datas
    add_filter(‘cfdb_form_data’, ‘chkValues’);

    BUT if i detect that a data is a spam, how not to save data ? right now, it’s cleaning my data but save it (even if it is blank).

    Any idea ?

    Thank you

    https://wordpress.org/plugins/contact-form-7-to-database-extension/

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

    (@msimpson)

    I think if you make your chkValues return null then it will not save. Try it and let me know. Thanks.

    Plugin Author Michael Simpson

    (@msimpson)

    …if for some reason that doesn’t work, another thing you can do is change the name of the form in your validation function to something like “spam” and go to the options page and list “spam” as a form not to save.

    Thread Starter wpwcm

    (@wpwcm)

    Thanks.
    The weird thing is that if i set up to null either the $formData->title (even doing unset($formData->title);) of the form or the return value, then it saves a value.

    i’ve playing around with the array described in the doc without success in my chkValues :
    $formData = (object) array(
    ‘submit_time’ => 1339365804.7815, // float Unix timestamp with microseconds
    ‘ip’ => ‘192.168.1.1’, // string IP address
    ‘user’ => ‘admin’, // string user name if submitter was logged in. May be null
    ‘title’ => ‘Form name string’,
    ‘posted_data’ => array(/* key=>value for each field in the form */),
    ‘uploaded_files’ => null
    );

    I’m doing something wrong but don’t find what….

    Plugin Author Michael Simpson

    (@msimpson)

    Post your chkValues function so I can see what you are talking about.

    Thread Starter wpwcm

    (@wpwcm)

    Thanks for helping 🙂

    function chkValues($formData) {
    // Change $formData
    if (isset($formData->posted_data[brochure_firstname])) {
    $formData->posted_data[brochure_firstname]=ucfirst(strtolower(safe_sql($formData->posted_data[brochure_firstname])));
    $formData->posted_data[brochure_email]=strtolower(safe_sql($formData->posted_data[brochure_email]));
    $formData->posted_data[brochure_name]=strtoupper(safe_sql($formData->posted_data[brochure_name]));
    $formData->posted_data[brochure_phone]=preg_replace(“#[^0-9]+#”,””,safe_sql($formData->posted_data[brochure_phone]));
    } else {
    $formData->posted_data[subscribe_email]=preg_replace(“#[^0-9a-z@\._\-]+#i”,””,strtolower(safe_sql($formData->posted_data[subscribe_email])));
    if (!filter_var($formData->posted_data[subscribe_email], FILTER_VALIDATE_EMAIL)) {
    $formData->posted_data[subscribe_email]=””;
    }
    }
    $formData->posted_data[‘uri’] = $_SERVER[‘REQUEST_URI’];
    return $formData; // be sure to return it
    }

    Plugin Author Michael Simpson

    (@msimpson)

    There is a bunch of stuff wrong in there. First, you aren’t quoting the names like brochure_firstname. Second, looks like a couple things wrong in the RegEx in both preg_replace. Be sure the function “safe_sql” is available. I tried to fix things how I think you want them:

    function chkValues($formData) {
        // Change $formData
        if (isset($formData->posted_data['brochure_firstname'])) {
            $formData->posted_data['brochure_firstname'] = ucfirst(strtolower(safe_sql($formData->posted_data['brochure_firstname'])));
            $formData->posted_data['brochure_email'] = strtolower(safe_sql($formData->posted_data['brochure_email']));
            $formData->posted_data['brochure_name'] = strtoupper(safe_sql($formData->posted_data['brochure_name']));
            $formData->posted_data['brochure_phone'] = preg_replace("/#[^0-9]+#/", "", safe_sql($formData->posted_data['brochure_phone']));
        } else {
            $formData->posted_data['subscribe_email'] = preg_replace("/#[^0-9a-z@._-]+#i/", "", strtolower(safe_sql($formData->posted_data['subscribe_email'])));
            if (!filter_var($formData->posted_data['subscribe_email'], FILTER_VALIDATE_EMAIL)) {
                $formData->posted_data['subscribe_email'] = "";
            }
        }
        $formData->posted_data['uri'] = $_SERVER['REQUEST_URI'];
        return $formData; // be sure to return it
    }

    PS you should take your preg_replace out into a test .php file where you put in an example input, print the replacement and see if you get what you want. When it is right, then put it into the function

    Thread Starter wpwcm

    (@wpwcm)

    Thank you Michael for your time.

    About regex, I’m used to use # instead of / since a long time (result is the same).
    Forgetting the ” for vars was definitely a bad writing (I did correct that).

    Sorry, I realize that i didn’t explain well the issue.
    data was corrected/changed well and saved.

    if i do the $formData->posted_data = null; then it’s cleaning the data from the form, but the form is still saving the “Submitted” the “Submitted Login” and “Submitted From” datas (all the others being empty).
    If data is ok, i want to keep these 3 submitted fields. but when it’s not ok, then i want nothing to be saved as it seems that $formData is not the only things saved (the three other fields).
    doing then $formData->posted_data[‘Submitted’] = “”; is deleting the value.
    but doing $formData->posted_data[‘Submitted Login’] = null;
    $formData->posted_data[‘Submitted From’] = null;
    doesn’t delete the values. and thus a new record is saved

    Thread Starter wpwcm

    (@wpwcm)

    the only solution I found is to put an exit(); before the “return $formData;”
    then, in that case, it’s not saving the info.

    but i found this solution inelegant ?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How not to save data when data is detected as bad’ is closed to new replies.