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