• Hello!

    I have on our page tournament-registrations – for each tournament a seperate contact form.

    Is it possible to make ONE contact form where the user can choose (with checkboxes) at which
    tournaments he wants to participate and then the data will stored automatically in all databases which he has selected?

    This would be an enormous relief for me and the participants.

    Thanks in advance!
    Andy

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

    (@msimpson)

    Based on Manipulating Form Data Before it is Saved,

    Assuming the values submitted in your checkboxes are the form names, I think this would work:

    require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CF7DBPlugin.php');
    
    function save_to_multiple_forms($formData) {
        $formName = 'your-form'; // change this to your form's name
        $fieldName = 'form-names-field'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            if (isset($formData->posted_data[$fieldName]) && is_array($formData->posted_data[$fieldName])) {
                $plugin = new CF7DBPlugin();
                $num_selections = count($formData->posted_data[$fieldName]);
                for ($idx = 0; $idx < $num_selections; ++$idx) {
                    $formData->title = $formData->posted_data[$fieldName];
                    if ($idx < ($num_selections - 1)) {
                        $plugin->saveFormData($formData);
                    }
                }
            }
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'save_to_multiple_forms');
    
    Thread Starter andreas.kastl

    (@andreaskastl)

    Thank you Michael!

    I have tried with this code but I think I made some mistake.

    Contactform: Nordcup_2017
    [checkbox* checkbox-839 “Verein 1” “Verein 2” “Verein 3” “Verein 4” “Verein 5” “Verein 6” “Verein 7”]

    ` $formName = ‘Nordcup_2017’; // change this to your form’s name
    $fieldName = ‘checkbox-839’; // change this to your form’s name

    Now when i trie this it creates always a DB which has no name and is empty.

    I think it’s a similar mistake from me.

    MANY THANKS!!!!

    Plugin Author Michael Simpson

    (@msimpson)

    My code suggestion might not be quite right. You may have to play around with it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Save data depending of checkboxes in different databases’ is closed to new replies.