I cannot seem to find a solution, neither here nor Google. A client requested to have ONE name field in his CF7 Form but once the email is sent it needs to bcome TWO fields.
Example: [your-name] becomes [first-name] [surname] somewhere hidden in the form.
How is this even possible?
EDIT
I have built something with webhooks but for some reason it does not submit the data.
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
$posted_data["first_name"] = $first_name;
etc. I don't know CF7 well enough to know if that's going to work though. – Rup May 17 at 13:41