I would like to dynamically set the email recipient of a wpcf7 contact form.
The step by step process of the user journey is as follows:
The website provides multiple law services. A user goes into one of these service pages and within each service page there is an element which generates a loop for a custom post type called 'Solicitor'. Each solicitor which provides this service is displayed in a grid.
The user clicks on a call to action on the solicitor they wish to contact.
This triggers a popup (I'm using the Popup Maker plugin) This popup contains a simple wpcf7 form with inputs such as name, email, message, etc. The user fills in the form and sends the contact form.
I want the contact form input to be emailed to the solicitor which the user clicked on.
My approach has been to get all contact solicitor call to actions and loop through them. Each of these call to actions have a data-id attribute with the corresponding solicitor post-id.
const solicitorContactBtns = document.querySelectorAll('.cta');
solicitorContactBtns.forEach(solicitorContactBtn => {
solicitorContactBtn.addEventListener('click', () => {
// Was planning on getting the data-id attribute (post-id) and somehow setting the recipient email to the 'email' custom field of this post-id. Not sure how to do this or if this is event possible?
});
});
I may be using the wrong approach any help is much appreciated.