Replies: 0
I have built something with webhooks but for some reason it does not submit the data. I want to achieve that the [your-name] field is being split into 2 hidden fields. This is to eradicate too many steps in CF7
add_action( 'wpcf7_before_send_mail', 'wpcf7_strip_name', 10, 1 );
function wpcf7_strip_name($contact_form){
$submission = WPCF7_Submission::get_instance();
$posted_data = $submission->get_posted_data();
if ($posted_data["your-name"]){
$name = trim($posted_data["your-name"]);
$last_name = (strpos($name, ' ') === false) ? '' : preg_replace('#.*\s([\w-]*)$#', '$1', $name);
$first_name = trim( preg_replace('#'.$last_name.'#', '', $name ) );
// Set default value for last name if none is provided
if ($last_name == NULL ){
$last_name = "Not Provided";
}
}
}
In my Contact Form I have the following hidden fields
[hidden first_name]
[hidden last_name]
Both fields are declared in the email too as [first_name] [last_name] but the name-stripping does not pull through