Home › Forums › Front-end Issues › 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?
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! 😉
The topic ‘Multiple acf_form's on one Page’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.