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/ , I read this article 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/
-
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.com)
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?MMM I use the code with the plugin 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
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 fuctionfunction 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');…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() callThat way the form_with_pipes_handler() is available, and you can turn on or off the actual actions independently.
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
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')) {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?
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”]Also Im using a radio button….
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
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; }oh thanks a lot!!! that works 😀
The topic ‘Get the second value’ is closed to new replies.