Storing PHP generated data in CF7 custom fields not working
-
I’m attempting to create an email verification workflow in CF7. Seems like a pretty common task as form submissions from users often need to be validated as their own. But I cannot find an example that successfully writes an update to submission data. I can modify the mail body just fine. But populating the same generated verification code in the user submission data (as viewed in Flamingo) does not work no matter what I’ve tried. The following code does NOT function as expected:
add_action('wpcf7_before_send_mail', 'custom_email_confirmation'); function custom_email_confirmation($contact_form) { if ($contact_form->id() == 19377) { // Process only the desired CF7 form submissions $submission = WPCF7_Submission::get_instance(); if ($submission) { $posted_data = $submission->get_posted_data(); $verification_code = wp_generate_password(20, false); // Generate a random code $_POST['vcode'] = $verification_code; // Writing code to [hidden vcode] field fails! $posted_data['vcode'] = $verification_code; // Tried other way, no luck either $mail = $contact_form->prop('mail'); $mail['body'] = str_replace('[verification-link]', 'Please click the following link to verify your email: '.site_url().'/verify-email/'.$verification_code, $mail['body']); $contact_form->set_properties(array('mail' => $mail)); //this part works fine } } return $contact_form; }
Appreciate anyone’s help to understand what I’m doing wrong here.
- The topic ‘Storing PHP generated data in CF7 custom fields not working’ is closed to new replies.