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( 
    				)) ; ?>
    				<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.
    				<button type="submit">Save Draft</button>

    The filter:

    add_filter( 'acf/pre_save_post', 'merge_pre_save_post', 10, 1 );
    	function merge_pre_save_post( $post_id ) {
    		if( is_admin() ) :
    		//Set the status based on the form
    		if( $_POST['acf']['submitted'] == 'submitted' ) : $status = 'submitted'; else : $status = 'draft'; endif;
    		print_r( $_POST );
    		echo $status;
    		//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,
    			) );
    		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.