Dynamically Setting Form Recipients Based on ACF Fields

By: Andrew Rice | Asked: 03/19/2025
ForumsCategory: General questionsDynamically Setting Form Recipients Based on ACF Fields
Andrew RiceAndrew Rice asked 1 month ago

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

  1. Create your form that will be embedded across multiple posts
  2. Add a hidden field to store the recipient email (note its ID for the code)
  3. Add the code above to your theme's functions.php file (or a custom plugin)
  4. In your form's email notification settings, use the hidden field as the recipient:
    • Go to Form Settings → Actions & Notifications
    • Edit your email notification
Attachments
1 Answers
Victor Font Staff answered 1 month ago

This is the line in the code that retrieves the email address from ACF: $recipient_email = get_field('recipient_email', $post->ID). Is the ACF email field named "recipient_email"?

Andrew RiceAndrew Rice replied 1 month ago

<p>aha...nope, its simple "email". thank you!! that did it.  I am obviously NOT a php wizard. :)</p>

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right