Replies: 0
I have a table (id=1) that shows some data with links in the first column that opens a “Contact Form 7” form and I need it to pull an email address from another table (id=2) but I don’t want the email address exposed so I am sending a number in the URL from table 1 (example: …/page-name/?em_id=2) these “IDs” will be added by me into table 1 and align with the correct row in table 2.
I was thinking of using code that dynamically changes the recipient email address like this one: https://www.frontendhero.dev/tutorial/dynamic-contact-form-7/
I am not sure how exactly to tell it to grab the “em_id” from the URL and filter the rows from table 2 to only pull column 4 of the row specified in the “em_id” in this case it would be row 2, column 4 and use that email address as the “$recipient_email”.
I am not great at code but I do know I need some sort of filter in my functions.php to grab this data and send it to the form but not exactly sure how to bring it all together, this is what I have so far:
$email_id = $_GET['em_id'];
$atts['row'] = $email_id;
$atts['column'] = 4;
$atts['cache_table_output'] = false;
$table_id = 2;
but I need help to figure out how to make it all work with the contact form code and the “$recipient_email”:
// hook into wpcf7_before_send_mail
add_action( 'wpcf7_before_send_mail', 'cf7dynamicnotifications'); // Hooking into wpcf7_before_send_mail
function cf7dynamicnotifications($contact_form) // Create our function to be used in the above hook
{
$submission = WPCF7_Submission::get_instance(); // Create instance of WPCF7_Submission class
$posted_data = $submission->get_posted_data(); // Get all of the submitted form data
// set the email address to recipient
$mailProp = $contact_form->get_properties('mail');
$mailProp['mail']['recipient'] = $recipient_email;
// update the form properties
$contact_form->set_properties(array('mail' => $mailProp['mail']));
}
Any help would be appreciated!