• Resolved tbw75

    (@tbw75)


    I am trying to make the filter shown on “http://cfdbplugin.com/?page_id=747” work for my website.

    Here’s the background:  I’m using Fast Secure Contact Form.  I’ve named my form label as “register”.  The FSCF plugin tells me that the shortcode is [si-contact-form form=’3′] but in order to make my form appear on a page I needed to use [si-contact-form form=”3″]
    A very minor point, but I’m a beginner and I only raise this slight difference in case a similar issue might be causing the problem below.

    I have set up a hidden field on the FSCF called “Passcode” which I would eventually like to use as a unique identifier, but at this stage I am simply trying to make any value pass through to the Passcode column of my database.

    I have the Contact Form to DB extension.   The form works fine, it submits values to each of the other fields of the CFDB. The Passcode column-header is present on the CFDB and, as expected, at this stage there are no values within the column because it is a hidden field.

    Next I installed Shortcodes, Actions and Filters with the intention of adding a filter to create a Passcode which will be submitted to the database.  I have added the code shown below, and it is activated.  For now you’ll see I have set the value of Passcode as a fixed value = 192 to test if the filter works but no value is feeding into CFDB under the Passcode column.  Given the minor issue i mentioned above with ‘ and “, I have tried LOTS of different variations of the following code but no success.  So any advice is gratefully received!

    Within the code below I have also tried “form” instead of “title”.

    I have also tried the form label “register” instead of the number “3”.

    Having tried MANY slight tweaks to the shortcode it seems like I am missing something really simple?  As i mentioned, I am a beginner so I might be missing something more fundamental. I’ve named the filter shortcode create_uniqueID.  Do I need to enter the shortcode of the filter on a page maybe?  Or maybe I need to select a particular option within the shortcode “execute only for” dropdown list?

    function myFilter($formData){
        $formName = ‘3’;
        if ($formData && $formName == $formData->title) {
            $formData->posted_data[‘Passcode’] = ‘192’;
        }
        return $formData;
    }

    add_filter(‘cfdb_form_data’, ‘myFilter’);

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

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

    (@msimpson)

    Thanks for writing a detailed account. $formName is not going to be ‘3’, it will be the name of the form. Go to CFDB and look at form submissions. In the drop-down box to select which form data to look at, you will see the name of your form. Use that.

    You wrote that your form label was “register”. Then you should see “register” in the CFDB drop down list and “Form 3: register” in FSCF form definition. If you have extra spaces in the name, that could be the problem.

    You can also temporarily remove the “if” check in your code to see that it is working. (then this will be applied to all form submissions).

    function myFilter($formData){
        $formData->posted_data['Passcode'] = '192';
        return $formData;
    }
    add_filter('cfdb_form_data', 'myFilter');
    Thread Starter tbw75

    (@tbw75)

    Hi Michael,

    Thanks very much for your response. So I have used the code you suggested (removing the if check). I’ve made new submissions, but still no values appear under the column Passcode in CFDB.

    Have you got any other tips for working out why it isn’t working?

    Plugin Author Michael Simpson

    (@msimpson)

    Your code is activated in Shortcodes, Actions and Filters ?

    Thread Starter tbw75

    (@tbw75)

    Yes, it’s definitely activated. And I’ve kept the code simple as you suggested above, so that the form name is not an issue.

    On CFDB, the other (unhidden) field values all appear ok after each submission, but the Passcode column does not have any values.

    I also tested using the filter to change the value of a submitted unhidden field, but the code didn’t change their submitted values – the submitted values of unhidden fields feed through unaltered to the CFDB.

    It seems that my shortcode filter isn’t having any impact on submitted data before it is saved – any other tips are gratefully received!!

    Thread Starter tbw75

    (@tbw75)

    I probably should’ve also mentioned, when I said I am testing it on submitted data, I mean new submissions.

    Plugin Author Michael Simpson

    (@msimpson)

    It seems like the code is not being called. Is this the only “myFilter” function you have defined? I tried the following and it works for me:

    function passcode_filter($formData) {
        $formData->posted_data['Passcode'] = '192';
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'passcode_filter');
    Thread Starter tbw75

    (@tbw75)

    Thanks for your help Michael – I’ll give that a shot.

    Cheers

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Adding Form Data before it is saved’ is closed to new replies.