• Resolved djekanovic

    (@djekanovic)


    Hello!

    I went trough docs and tried many exmaples but couldn’t get it to work.
    Basically here is what I need
    – Custom post type with some ACF data
    – one of which is like member email

    – On that single page those fields are accessible via get_field and are dynamic based on page.

    I have an ACFE form on that page, and I want the TO: email be dynamic based on that email field from ACF, how can I easily achieve that?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    In order to retrieve a metadata from the page where the form is being displayed inside an ACFE Form action hook, you have to set the post id in the get_field() function. Without that post id, the get_field() will try to retrieve the value of the field input inside the form.

    Here is an example with the acfe/form/submit/email_args hook (See documentation):

    add_filter('acfe/form/submit/email_args/action=my-email', 'my_form_email_args', 10, 3);
    function my_form_email_args($args, $form, $action){
    
        // retrieve the value of the field input named 'my_email' in the form
        $my_email = get_field('my_email');
        
        // retrieve the post id of the page where the form is displayed
        $post_id = $form['post_id'];
        
        // retreive the field named 'my_email' saved as metadata on the current page
        $my_email = get_field('my_email', $post_id);
        
        // set the 'to' argument
        $args['to'] = $my_email;
        
        // return
        return $args;
        
    }
    

    I would recommend to use acf_log($my_email) in order to log the variables values and check what is behind those get_field().

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Dynamic reciever “TO” email’ is closed to new replies.