Title: Get the second value
Last modified: August 31, 2016

---

# Get the second value

 *  Resolved [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/)
 * Hi there,
 * I’m using tha last version of the contact form 7 plugin and I’m using “Selectable
   Recipient with Pipes”[http://contactform7.com/selectable-recipient-with-pipes/](http://contactform7.com/selectable-recipient-with-pipes/),
   I read this article [http://cfdbplugin.com/?page_id=804](http://cfdbplugin.com/?page_id=804)
   but In my radio options I will repeat some emails, and I need to get the correct
   values, in the article is said that the code doesnt work with the last version
   of contactform7, Do you have the correct code? How I can get it?
 * Please, thanks in advance
 * [https://wordpress.org/plugins/contact-form-7-to-database-extension/](https://wordpress.org/plugins/contact-form-7-to-database-extension/)

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

 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158869)
 * There is nothing to get. The code works with the latest version of CF7 but due
   to a limitation in CF7, repeating emails won’t work right. Not in this version
   or any other. The work-around explained in that article is to append some text
   to the email address which is ignored by the email system but makes the emails
   unique (e.g. email**+location1**[@example](https://wordpress.org/support/users/example/).
   com)
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158919)
 * Oh thanks a lot,
    function location_form_handler($formData) { $formName = ‘Pipes’;//
   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); } What can I do if I have more
   than one form with pipes? I have to create more functions?
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158937)
 * MMM I use the code with the plugin [https://wordpress.org/plugins/add-actions-and-filters/](https://wordpress.org/plugins/add-actions-and-filters/)
   but it doesnt work my cod is function location_form_handler($formData)
    { $formName
   = ‘Trámites ante la oficina AFSDP’; // change this to your form’s name $fieldName
   = ‘your-recipient’; // change this to your field’s name $newFieldName = $fieldName.‘
   _email’; return form_with_pipes_handler($formName, $fieldName, $newFieldName,
   $formData); }
 * 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]; $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;}
 * add_filter(‘cfdb_form_data’, ‘location_form_handler’);
 * it’s activated and it has a check in “Execute also on Dashboard Pages” but I 
   can see the changes
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158966)
 * I can’t follow your unformatted code. Use the “code” button to format it when
   posting.
 * If you have more than one form, say “FORM1” and “FORM2”, do the following:
    –
   Put in the function form_with_pipes_handler() as shown in the documentation –
   Create a version of the function form_with_pipes_handler() for each form — Change
   the name of the function for each. – Add an “add_filter” call for each fuction
 *     ```
       function location_form_handler_FORM1($formData)
       {
           $formName = 'FORM1'; // 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_FORM1');
   
       function location_form_handler_FORM2($formData)
       {
           $formName = 'FORM2'; // 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_FORM2');
       ```
   
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158967)
 * …if you are using Add Shrotcode, Actions and Filters plugin, I suggest
    – Add
   a “action” and put just the form_with_pipes_handler() function in it. Do this
   first – Add an action for location_form_handler_FORM1() its add_filter() call–
   Add an action for location_form_handler_FORM2() its add_filter() call
 * That way the form_with_pipes_handler() is available, and you can turn on or off
   the actual actions independently.
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158972)
 *     ```
       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];
               $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;
       }
   
       add_filter('cfdb_form_data', 'location_form_handler');
       ```
   
 *     ```
       function location_form_handler($formData)
       {
           $formName = 'Trámites ante la oficina AFSDP'; // change this to your form's name
           $fieldName = 'your-recipient'; // change this to your field's name
           $newFieldName = $fieldName . '_email';
           return form_with_pipes_handler($formName, $fieldName, $newFieldName, $formData);
       }
       ```
   
 * This is my code, but it doesnt work, mm I have 2 forms on the same page, and 
   in both of them I’m using the pipes, but with only one I used the functions and
   it doesnt work :c
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7158975)
 * I’ll assume that you are using form_with_pipes_handler() copied exactly from 
   the example. Double check that.
 * Double check the code is activated and saved in Add Shortcode, Actions & Filters.
 * Double check the form name is exactly correct. You can temporality disable the
   check that the form name matches. If you do that and it starts to work, then 
   you know the form name is wrong.
 *     ```
       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')) {
       ```
   
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7159064)
 * Mmm it still doesnt work…
 * the first function is
 *     ```
       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];
               $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;
       }
       ```
   
 * then
 *     ```
       function location_form_handler($formData)
       {
           $formName = 'Trámites ante la oficina AFSDP'; // change this to your form's name
           $fieldName = 'your-recipient'; // 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');
       ```
   
 * then
 *     ```
       function location_form_handler_form2($formData)
       {
           $formName = 'Trámites ante entidades públicas y privadas'; // change this to your form's name
           $fieldName = 'tramiteprivadapublico'; // 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_form2');
       ```
   
 * They has a check in “Activated and Execute also on dashboard pages”,
 * I have contact form version 4.4 and contact form db 2.10.1, What else can I do?
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7159065)
 * also I comment the lines that you said and It did not work, my forms are :
 * [contact-form-7 id=”56773″ title=”Trámites ante entidades públicas y privadas”]
   [
   contact-form-7 id=”56758″ title=”Trámites ante la oficina AFSDP”]
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7159066)
 * Also Im using a radio button….
 *  Plugin Author [Michael Simpson](https://wordpress.org/support/users/msimpson/)
 * (@msimpson)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7159113)
 * I spent some time debugging an example of this. The Radio button seems change
   the CF7 data structure a bit. I had to make an update to form_with_pipes_handler()
   shown below. I also updated it on [http://cfdbplugin.com/?page_id=804](http://cfdbplugin.com/?page_id=804)
 *     ```
       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;
       }
       ```
   
 *  Thread Starter [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * (@jonadeis)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7159114)
 * oh thanks a lot!!! that works 😀

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

The topic ‘Get the second value’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/contact-form-7-to-database-extension_ffffff.
   svg)
 * [Contact Form DB](https://wordpress.org/plugins/contact-form-7-to-database-extension/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7-to-database-extension/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7-to-database-extension/reviews/)

## Tags

 * [pipes](https://wordpress.org/support/topic-tag/pipes/)

 * 12 replies
 * 2 participants
 * Last reply from: [SrGato29](https://wordpress.org/support/users/jonadeis/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/get-the-second-value/#post-7159114)
 * Status: resolved