I want to create a single form that can be embedded on multiple posts and dynamically pull the recipient email from an ACF field in each post.
Kolahn from Formidable gavce me the code below, but it is not working. I assume becasue there (seems to me) to be no reference to the ACF field for the email address.
I HAVE setup the embeded form, and have inout the correct field ID of 227 (u can se that in the attached screenshot)
Instructions from Formidable below:
-
Here's how to set it up:
Using the frm_setup_new_fields_vars hook
This approach uses a hidden field in your form and populates it with the ACF value from the current post:
https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/#kb-usage
An example of this could be:
add_filter('frm_setup_new_fields_vars', 'set_dynamic_recipient_field', 20, 2);
function set_dynamic_recipient_field($values, $field) {
// Replace 123 with your hidden email field ID
if ($field->id == 123) {
global $post;
if ($post && function_exists('get_field')) {
$recipient_email = get_field('recipient_email', $post->ID);
if ($recipient_email) {
$values['value'] = $recipient_email;
}
}
}
return $values;
}
Implementation Steps