Support

Account

Home Forums Front-end Issues Multiple acf_form's on one Page

Solving

Multiple acf_form's on one Page

  • You guys are awesome, BTW. Seriously. This plugin saves insane amounts of time. here’s my issue:
    I placed a different acf_form into a variety of lightbox’s (11 in total) on a page template. Each form creates a different post type and has different form fields. The problem that I am running into is that when I click submit on one form it’s picking up required fields from other forms in other lightboxes requiring me to input info into all of the required fields before it will submit. When there are no required fields on any of the forms it works like a charm.

    Is there a way to check each form individually for required fields, even though there are multiple acf_forms on the page?

    Is this even possible?

  • I would want to know the solution to this please!

  • Hi SaskiaB! I solved it by adding a hidden input field to the form.

    So in my page:

    $bio_args = array(
    				
    				'post_id' => 'new_artist',
    				'field_groups' => array( 55 ),
    				'submit_value' => 'Submit my Bio',
    				// 'return' => 
    				'html_after_fields' => '<input type="hidden" name="post_type" value="frp_artist">'
    			);
    			?>
                <?php acf_form( $bio_args ); ?>

    Then in my functions:

    function wnc_bio_frontend( $post_id )
    {
     	// check if this is to be a new post
        if( $post_id != 'new_artist' )
        { return $post_id; }
        // Create a new post
    	$tax_actors = array(
    		$_POST['fields']['field_5439adfebbbcb'],
    	);
        $post = array(
            'post_status'  => 'pending',
            'post_title' => $_POST['fields']['field_5439aa052a606'],
            'post_type'  => $_POST['post_type'],
    		'tax_input' => $tax_actors,
    	);  
        // insert the post
        $post_id = wp_insert_post( $post ); 
        // update $_POST['return']
        $_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );    
        // return the new ID
        return $post_id;
    }
    
    add_filter('acf/pre_save_post' , 'wnc_bio_frontend' );

    Notice the “post type” hidden field. I hope that helps!

  • Hi thejameswilliam,

    First of all thanks for your reply.

    If I am not using this to make a new item than the id is returned, wright!?, but how does the hidden field make a difference here then???

    I am sorry, I pretty new at this stuff so please be patient, thanks for your time! 😉

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

You must be logged in to reply to this topic.