• Resolved jpldev

    (@jpldev)


    Hi,

    We are having some trouble doing the following.

    We need a field in ACF to be filled on form submit with the post id of the page the form was on when it is submitted.

    The first idea we had was to map this post id to a ACF field in the form settings, but we was surprised to find to that while you can map all built in wordpress fields, you are unable to map ACF fields and can only toggle them on or off in the form settings. This feels really limiting to me, as the template tag that we need is in the cheatsheet and would get the job done if we could only map it to the acf field.

    Next we tried the form/post action, but from what we could tell, this only contains built in wordpress fields also, so no options for changing acf field values before the form/post action adds them to DB.

    ACF Extended is great, it provides so much benefit to our dev workflow for client sites, which is why we were so shocked that this feature wasn’t in the plugin. Maybe we have missed a step that allows us to map fields, or at least hook into them.

    Is it not possible to do what we want (as said at the start of this post) – Or have we simply missed a step or misunderstood how something works. Please let me know, I and the rest of the team want to get this fixed.

    If this isn’t a feature, I think it definitely should be! – Looks like the ground work is already in for allowing mapping of built in wordpress fields, just need to add the same for ACF fields.

    Looking forward to hearing from you. Thanks.

    • This topic was modified 5 years ago by jpldev.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The ACF Extended Form module is an enhancement of the native ACF Form feature. This means that the form render, validation & submission follow the ACF logic (same as in the backend). The advantage of this method is that you can use any of the ACF hooks for the front-end form, such as:

    In addition of this native hooks, ACF Extended add new filters/actions for even more control over the form behavior. For example you can validate the whole form (validate one field against an another one) or perform an action on form submission and interact with fields values more easily.

    You’ll find those new hooks in the documentation here.

    Regarding what you’re trying to achieve, you can simply use the Post Action: Submit Hook which let you run a script when a post is created/updated. Usage example:

    add_action('acfe/form/submit/post/form=my-form', 'my_form_submit', 10, 5);
    function my_form_submit($created_post_id, $type, $args, $form, $action){
        
        // Retrieve the post id of page where the form is displayed
        $page_id = $form['post_id'];
        
        // Update 'my_field' with $page_id on the created/updated post
        update_field('my_field', $page_id, $created_post_id);
        
    }
    

    While I understand it may look simple to just add ACF Fields mapping from the UI, this feature would add a whole new level of complexity since that would mean an admin could override any input enter by the user, from the backend. This would be even more complicated for complex fields like repeaters, flexible content or clones.

    This is why ACF Extended Form has tons of hooks at every stages of the from process (render, validation, submission), so developers can completely customize the form behavior, including for complex fields.

    I added the feature request on the Trello Board tho. I’ll take a look at it, see if it can be done within the UI.

    Hope it helps!

    Have a nice day!

    Regards.

    PS: Thanks for the kind review 🙂

    Thread Starter jpldev

    (@jpldev)

    Thanks for getting back to me so quickly.

    That is perfect, problem solved. Didn’t see those new hooks from ACFE.

    Brilliant work!

    Thanks.

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear it solved your problem 🙂

    Thanks for the compliment too!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘ACFE Form Mapping ACF Fields to Template Tags and other fields’ is closed to new replies.