Home › Forums › Front-end Issues › Front-End Form Save as Custom Status › Reply To: Front-End Form Save as Custom Status
Hi John,
Thank you for your reply–I have the checkbox as an added field outside of the actual ACF form. I did test the function (see revised function below to see how I tested) for a scenario with the checkbox both checked and unchecked. In each case, the variable $status is being set correctly. But, it’s not being set correctly on save.
The form:
<form id="new-program" class="new-program" action method="post">
<?php acf_form( array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'program',
),
'submit_value' => 'Submit Program',
'id' => 'new-program',
'post_title' => true,
'post_content' => false,
'form' => false,
'return' => $return_url,
'label_placement' => 'top',
'instruction_placement' => 'label',
'uploader' => 'basic',
'field_el' => 'ul',
'fields' => array(
'program-submission_blind_description',
'program-submission_blind_abstract',
'program-submission_blind_learneroutcomes',
),
)) ; ?>
<input type="checkbox" id="submitted" name="submitted" value="submitted" />
<label for="submitted" id="label-submitted">
I confirm that my submission is complete and ready for review. I understand that once I submit this program, I cannot edit it.
</label>
<button type="submit">Save Draft</button>
</form>
The filter:
add_filter( 'acf/pre_save_post', 'merge_pre_save_post', 10, 1 );
function merge_pre_save_post( $post_id ) {
if( is_admin() ) :
return;
endif;
//Set the status based on the form
if( $_POST['acf']['submitted'] == 'submitted' ) : $status = 'submitted'; else : $status = 'draft'; endif;
//FOR TEST ONLY
print_r( $_POST );
echo $status;
exit;
//Check if it's not a new post
if( $post_id != 'new_post' ) :
wp_update_post( array(
'post_id' => $post_id,
'post_status' => $status,
) );
//
else :
$post_id = wp_insert_post( array(
'post_status' => $status,
) );
endif;
return $post_id;
}
In both cases–checked and unchecked–the value for $status is correct; it’s just not being applied to the post correctly.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.