Support

Account

Home Forums Front-end Issues Usign hooks (acf_submit_form) with multiple different forms

Solved

Usign hooks (acf_submit_form) with multiple different forms

  • I would like to create different handlers for different forms, how can I have different forms handeled different ways?

    Right now I have a function:

    
    function my_acf_submit_form( $form, $post_id ) {
    handling stuff here
    }
    add_action('acf/submit_form', 'my_acf_submit_form', 10, 2);
    

    This handles one form. Now I want to create a new front end form, can I identify the form that is handeled – how? I could use if-clauses inside the above function if I could identify from what form is the data coming?

    I need to handle the data after user has submitted the form and the data is saved, that’s why I’m using the hook my_acf_submit_form.

  • Hi Hidieh:

    You can use the id parameter (one of the arguments passed to acf_form) to create a unique id for each of your forms. In your function triggered by the submit form action then use the global for acf_form to retrieve the ID value ($GLOBALS[‘acf_form’]).

    See Elliot’s responses in this thread (though the original question is different from what you are asking) for more detail:

    https://support.advancedcustomfields.com/forums/topic/acf_form-id-not-being-set-from-args/

    Hope this is helpful!

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Usign hooks (acf_submit_form) with multiple different forms’ is closed to new replies.