• Resolved richardu

    (@richardu)


    I’m using this shortcode [acfe_form name="my-form" my_data="abc"]

    I can use {form:my_data} in the UI for Post action/Save to set say, Post content

    How can I use {form:my_data} in the UI to set one of my ACF fields?

    Cheers, Richard

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter richardu

    (@richardu)

    I’m using a work-around for now: Since I don’t need the content field, I set that to {form:my_data} then use a save_post function to copy it to my ACF field.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    Unfortunately the ACFE Form doesn’t let you update a specific ACF Field value using a Template Tag from the UI at the moment. Template Tags can be only used in the ACFE Form UI settings, and within each Actions fields (such as Post Title, Post Content etc… for the Post Action).

    The workaround you found is quite ingenious, but there’s an easier way to achieve this in PHP.

    In fact when using any ACFE Form hooks, such as the Post Action Submit acfe/form/submit/post (See documentation), you’ll have access to the $form dataset, which contains your specific $form['my_data'].

    Using that value, you can update an ACF field programmatically with update_field().

    Here is a usage example:

    add_action('acfe/form/submit/post/form=my-form', 'my_form_submit', 10, 5);
    function my_form_submit($post_id, $type, $args, $form, $action){
        
        // retrieve 'my_data' from the $form dataset (aka: {form:my_data})
        $my_data = $form['my_data'];
        
        // update 'my_field' with 'my_data' value on the newly created 'post_id'
        update_field('my_field', $my_data, $post_id);
        
    }
    

    Hope it helps!

    Have a nice day!

    Regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set ACF Field with Template Tag in UI’ is closed to new replies.