Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter 972 creative

    (@toddedelman)

    Hi there

    Just an update – see the screenshots
    Email received: https://prntscr.com/c79zoo
    CF7 Form: https://prntscr.com/c7a081
    CFDB: https://prntscr.com/c7a0fj

    In the CFDB record, we’d like to see USA and not the email address of who received the message.

    Thanks,
    Todd

    Plugin Author Michael Simpson

    (@msimpson)

    See https://cfdbplugin.com/?page_id=804

    And you should probably remove the spaces around the pipes.

    Thread Starter 972 creative

    (@toddedelman)

    Hi Michael

    This worked, but a question…

    In your KB article, we took one field, chose to display before the pipes and added a new column in the DB for what was after the pipes.

    My need doesn’t require that I create a new column and record the data after the pipes. So what here in my code can I remove to eliminate the new column altogether?

    function form_with_pipes_handler($formName, $fieldName, $newFieldName, &$formData)
    {
        if ($formData &&
                $formName == $formData->title &&
                property_exists($formData, 'WPCF7_ContactForm') &&
                method_exists($formData->WPCF7_ContactForm, 'form_scan_shortcode')) {
     
            $scanned_form_tags = $formData->WPCF7_ContactForm->form_scan_shortcode();
            $emailSelected = $formData->posted_data[$fieldName];
            if (is_array($emailSelected) && count($emailSelected) == 1) {
                $emailSelected = $emailSelected[0];
            }
            $valueSelected = null;
            foreach ($scanned_form_tags as $tag) {
                if ($tag['name'] == $fieldName) {
                    foreach ($tag['raw_values'] as $rawValue) {
                        // value|email
                        $valuesArray = explode('|', $rawValue);
                        if (count($valuesArray) == 2 && $valuesArray[1] == $emailSelected) {
                            $valueSelected = $valuesArray[0];
                            break;
                        }
                    }
                }
                if ($valueSelected != null) {
                    break;
                }
            }
            if ($valueSelected != null) {
                $formData->posted_data[$fieldName] = $valueSelected;
                $formData->posted_data[$newFieldName] = $emailSelected;
            }
        }
        return $formData;
    }
    
    function location_form_handler($formData) // Use a different function name for each form
    {
        $formName = 'Contact Page'; // change this to your form's name
        $fieldName = 'location'; // change this to your field's name
        $newFieldName = $fieldName . '_email';
        return form_with_pipes_handler($formName, $fieldName, $newFieldName, $formData);
    }
    add_filter('cfdb_form_data', 'location_form_handler'); // ensure 2nd param matches above function name
    

    Thanks,
    Todd

    Plugin Author Michael Simpson

    (@msimpson)

    Sure. These are the key lines that set the fields.

    $formData->posted_data[$fieldName] = $valueSelected;
    $formData->posted_data[$newFieldName] = $emailSelected;

    I think you want to replace both of those lines with this line:
    $formData->posted_data[$fieldName] = $emailSelected;

    Thread Starter 972 creative

    (@toddedelman)

    Thanks for the reply.

    You helped but I was looking to record what’s before the pipe, so I used this:
    $formData->posted_data[$fieldName] = $valueSelected;

    delus

    (@delus)

    Hi,

    Need help on this. In my form there are 2 different dropdown menu both using pipe
    I would like to add another “fieldName” call “fileName2” How do I add from the current code.

    Thanks alot!

    Plugin Author Michael Simpson

    (@msimpson)

    Create another function like “location_form_handler” but name it something different like “another_form_handler” and fill in the code values:

    function another_form_handler($formData) // Use a different function name for each form
    {
        $formName = 'Contact Page 2'; // change this to your form's name
        $fieldName = 'another_Field'; // change this to your field's name
        $newFieldName = $fieldName . '_email';
        return form_with_pipes_handler($formName, $fieldName, $newFieldName, $formData);
    }

    Then register it to be called using that new name

    add_filter('cfdb_form_data', 'another_form_handler'); // ensure 2nd param matches above function name

    delus

    (@delus)

    Hi Michael,

    Sorry I didn’t put it clearly. I actually have it in one single form with 2 dropdown menu both with pipe, so I would like to add a new fieldname under same function.

    Thanks!

    delus

    (@delus)

    Hi Michael,

    Able to help on this?

    Thanks!

    Plugin Author Michael Simpson

    (@msimpson)

    I think I answered it. You can use the same value for $formName in the 2nd function.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Issue with data in DB when using Selectable Recipient with Pipes’ is closed to new replies.