• Resolved gvh

    (@gvh)


    This is in regards to Contact Form DB > Options > “Do not save fields in DB named (comma-separated list)” and Gravity Forms credit card field. When I put the credit card fields (Card Number,Expiration Date,Security Code,Cardholder Name) in the “Do not save” list, the columns are still in the admin area view of the submissions. The Card Number column contains the token code numbers generated by Stripe payments. The other credit card fields are empty as none of the credit card data should be touching my server as per Stripe protocol.

    It may be important to note that Stripe billing fields do not have the name attribute. Also, the Gravity forms credit card field is a so-called complex field. That is, it’s one field that contains various inputs for the Card Number, Expiration Date, etc.

    I would prefer not to be storing these credit card tokens codes in the CFDB database. Also, it would be nice if I could get rid of the credit card columns in the admin area altogether to make the table easier to work with.

    Is there a way to do this?

    Thanks for the fantastic plugin.

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter gvh

    (@gvh)

    Hi.

    I tried this.

    add_filter('cfdb_form_data', 'remove_field');
    function remove_field($formData){
    	$formName = 'myform';
    	if ($formData && $formName == $formData->title) {
    	    unset($formData->posted_data['Card Number']);
                unset($formData->posted_data['Expiration Date']);
                unset($formData->posted_data['City']);
    	    unset($formData->posted_data['Submitted From']);
    	}
        return $formData;
    }

    It prevents CFDB from putting the ‘City’ field in the database, but none of the other three. The same is true when you put them in the comma-separated list on the options page.

    Plugin Author Michael Simpson

    (@msimpson)

    That is surprising. Are you sure the spelling and case is right for each field name?

    PS, this will not work for ‘Submitted From’ but should for the other 3.

    Thread Starter gvh

    (@gvh)

    Thanks Michael:

    Good to know that this should be doable and that ‘Submitted From’ is behaving normally.

    I have the spelling and case correct. I can add and unset all my columns easily using your documentation, page_id=747. But the credit card fields don’t work. I know that Stripe tokens are not straight forward to unset as is also the case with session variables. But credit card data in the CDFB database shouldn’t also carry these traits, should it?

    Any direction you can give would be greatly appreciated.

    Oh yeah. Could you tell me why ‘Submitted From’ cannot be removed?

    Thanks again.

    Plugin Author Michael Simpson

    (@msimpson)

    The “Submitted From” field is generated by CFDB after the cfdb_form_data filter is called. So it does not yet exist at the time your code is called.

    To debug this, use the code below. It adds a ‘List of fields’ column so we can see all the known fields.

    add_filter('cfdb_form_data', 'remove_field');
    function remove_field($formData){
        $formName = 'myform';
        if ($formData && $formName == $formData->title) {
    
            // DEBUG: Create a new field for to see all the names of the fields we have
            $formData->posted_data['List of fields'] = '"' . implode('", "', array_keys($formData->posted_data)) . '"';
    
            // Remove some fields
            $fieldsToRemove = array('Card Number', 'Expiration Date', 'City');
            foreach ($fieldsToRemove as $fieldName) {
                if (isset($formData->posted_data[$fieldName])) {
                    unset($formData->posted_data[$fieldName]);
                }
            }
        }
        return $formData;
    Thread Starter gvh

    (@gvh)

    Thanks for the debug. Sorry for my slow response.

    The ‘List of Fields’ columns shows all of the credit card fields but the unset didn’t remove them.

    I noticed that Gravity Forms does not show the credit card fields in their entries ($entry). Could this have something to do with it? Or could I somehow use this fact with the gravity after_submission hook to limit the data CFDB puts in its database to just what is found in $entry? Or perhaps that’s a wild idea.

    Thanks for the help Mike. Really appreciated.

    Plugin Author Michael Simpson

    (@msimpson)

    In your function your are working on a copy of the submitted data, so you should be able to change it without Gravity forms impacting it.

    Given that you got a 'List of fields' that includes
    "Card Number", "Expiration Date", "City"
    (no extra spaces or anything inside the quotes) then I’m baffled.

    If you change this:

    foreach ($fieldsToRemove as $fieldName) {
                if (isset($formData->posted_data[$fieldName])) {
                    unset($formData->posted_data[$fieldName]);
                }

    to:

    foreach ($fieldsToRemove as $fieldName) {
                $formData->posted_data[$fieldName] = '';

    does it give you blank entries in those columns? Or are there new columns?

    Thread Starter gvh

    (@gvh)

    Thanks Michael. This one is resolved.

    You were right. There were spaces. Every credit card related field had a space before the first letter. I didn’t notice them this morning in the ‘List of Fields’. I had to copy/paste the field content to and editor to see them.

    I can use the Options in CFDB to remove all of the columns except one called “Cardholder’s Name”. I have no idea where that ” ‘s ” came from because it’s not in the Gravity Form anywhere I can see. The ” ‘ ” causes the plugin to put a “/” in front of it (I’ve seen this before somewhere else). But I can get rid of the column using your ‘cfdb_form_data’ hook in the php.

    Thanks so much.

    CFDB definitely has the best support of any plugin on the repo!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Gravity Forms and CFDB "Do not save fields"’ is closed to new replies.