• Hello, I am using Contact Form 7, and I was wondering if it is possible to save multiple form fields into the same column. For example, is it possible to have:

    [email email-1]
    [email email-2]
    [email email-3]

    and then save them all into a column named ‘Email’, each entry in a new row? I already know about Changing Form Data Before it is Saved, but this saves the data into only one row.

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

    (@msimpson)

    I suppose you could trick this out to work this way. Using the link you cited, install a filter function. In it, prepare three versions of the data structure for submission. Directly insert the first two and return the last one for the regular mechanism to insert it.

    To directly insert the first two, you basically need to:

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CF7DBPlugin.php');
    $cfdb = new CF7DBPlugin();
    $cfdb->saveFormData($formData1);
    $cfdb->saveFormData($formData2);

    Thread Starter Moondrop

    (@moondrop)

    Thanks for the reply Michael! Unfortunately, I have not been able to get it working. I always receive only one submission entry in the database. Could you give me an example of preparing one version of the data structure, and then inserting it?

    Once again thank you for your help!

    Plugin Author Michael Simpson

    (@msimpson)

    I tried the following, but it seems to hang for me on the call to $cfdb->saveFormData($formData);

    Try it and see if your luck is any better.

    functions.php

    function make_into_3_form_submissions_filter($formData)
    {
        $formName = 'three_emails'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CF7DBPlugin.php');
            $cfdb = new CF7DBPlugin();
    
            $email1 = $formData->posted_data['email-1'];
            $email2 = $formData->posted_data['email-2'];
            $email3 = $formData->posted_data['email-3'];
    
            unset($formData->posted_data['email-1']);
            unset($formData->posted_data['email-2']);
            unset($formData->posted_data['email-3']);
    
            $formData->posted_data['Email'] = $email1;
            $cfdb->saveFormData($formData);
    
            $formData->posted_data['Email'] = $email2;
            $cfdb->saveFormData($formData);
    
            $formData->posted_data['Email'] = $email3;
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'make_into_3_form_submissions_filter');

    Thread Starter Moondrop

    (@moondrop)

    Hi Michael, I am sorry for the very late reply. I tried the code you wrote, and sadly it hangs for me as well. Thank you for answering however.

    Apologies for bringing this back but it seemed the nearest topic on the issue I’m trying to resolve – that is to post multiple entries to the same form Db from a single form.

    I don’t pretend to fully understand these things, but having played around with this for a few hours it seems that the problem is that in the above example the saveFormData lines are activating this filter again, causing a continuous loop – hence the hang up.

    I’ve not yet decided on the implementation in my project (I’m just scoping at the moment) but adding an additional check in the ‘if’ statement for something that appears (or doesn’t) in the first entry only seems to do the trick.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Don’t apologize but do start your own topic instead.

    https://www.ads-software.com/support/plugin/contact-form-7-to-database-extension#postform

    Adding to someone else’s 6 month old topic is not the way to get support for your problem.

    Plugin Author Michael Simpson

    (@msimpson)

    I think the infinite loop problem is correct.

    To make it work, I think instead you would need to do this (I haven’t tried it)

    1. In the admin -> Contact Form DB -> Options list your form as one NOT to be saved.
    2. Instead of the “add_filter” call in the above code:
    – For CF7: add_action('wpcf7_before_send_mail', 'make_into_3_form_submissions_filter');
    – For FSCF: add_action('fsctf_mail_sent', 'make_into_3_form_submissions_filter');

    I started on this issue myself and seem to have found a solution, I posted it in this thread…
    https://www.ads-software.com/support/topic/create-new-record-for-each-selection-in-a-submitted-form?replies=3#post-4613418

    Basically stopping the looping by checking for a field that only exists the first time around – which seems to do the trick.

    I’ve used this to submit multiple records to a new form database thats linked to the original by an id. eg. Mr Smith makes 4 seperate bookings.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Contact Form 7 to Database Extension] Saving multiple form fields into the same column’ is closed to new replies.