I’m trying to manipulate the data sent in a contact form created by contact form 7.
Users select a product, which then sets a hidden text field with the value of all product id’s that are selected, separated from a comma.
I am trying to then change these ID’s to anhor links with the product’s title, all separated by a comma.
This is the code I have at the moment:
add_action('wpcf7_before_send_mail', 'my_wpcf7_before_send_mail');
function my_wpcf7_before_send_mail($form) {
$submission = WPCF7_Submission::get_instance();
$wpcf7 = WPCF7_ContactForm::get_current();
if ($submission) {
$data = $submission->get_posted_data();
if (empty($data)) {
return;
}
$extras = explode(',', $data['extras']);
$extras_html = '';
foreach ($extras as $extra) {
if ($extra != '') {
$extras_html .= '<a href="'.get_permalink(preg_replace('/s+/', '', $extra)).'">'.preg_replace('/s+/', '', $extra).'</a> ';
}
}
$data['extras'] = $extras_html;
}
$wpcf7->set_properties(array(
'mail' => $data
));
}
At the moment, the form simply fails to send.
All variations I have tried simply don’t manipulate the HTML.