Support

Account

Home Forums ACF PRO acf_form + acf/save_post > get the form id

Helping

acf_form + acf/save_post > get the form id

  • Hi there,

    I have a page that uses multiple acf_form instances to do various actions on the front-end. I would like to isolate acf/save_post so that it only targets one form at a time.

    I’ve started this by checking to see if a particular form field that’s unique to one particular acf_form is not empty to do so, like:

    
    function my_action($my_cpt_id) {
    	$my_field_1 = get_field('123456789',$my_cpt_id); // Field In Form A
    	if(!empty($my_field_1)){
    		// DO STUFF A
    	};
    	$my_field_2 = get_field('987654321',$my_cpt_id); // Field In Form B
    	if(!empty($my_field_2)){
    		// DO STUFF B
    	};
    }
    add_action('acf/save_post', 'my_action', 20);
    

    Instead of checking against a field, can I target the form itself directly?

    Thanks in advance

  • Do each of the forms form tags, meaning they are separate forms or are they all included inside a single form. By default each acf_form() is a separate form and must be submitted separately unless you’ve set the ‘form’ argument to false. If you have not done this then the fields of one form will not be submitted with another form.

    If you do have them all in one forms, then there isn’t any way to tell which fields go with a certain form except to check each field key. If each form is a separate field group then the “parent” of each top level field object will be the field group key. But there isn’t any way to trigger a different filter based on this information that I know of.

    Not sure if any of this will help you or not.

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

The topic ‘acf_form + acf/save_post > get the form id’ is closed to new replies.