Support

Account

Home Forums ACF PRO Frontend form submitting to custom post type Reply To: Frontend form submitting to custom post type

  • Here is my template code:

    <?php
    /**
     *
       Template Name: test form Full Width
     *
     * Description: A page template without the left or right columns
     * @package flat_responsive
     * @since 1.0.0
     */
    acf_form_head(); 
    get_header(); ?>
    
    	<div id="primary">
    		<div id="content" role="main">
    
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    				
    		  <h1><?php //the_title(); ?></h1>
    				<?php
    				if(isset($_GET['updated'])){
    					if($_GET['updated'] == 'true'){
    						echo '<p style="color:green;font-weight:bold">The file details have been submitted.</p>';
    					} 
    				} 
    				?>
    		  		<?php 
    				  acf_form(array(
    					  'id' => 'POV-Travel',
    					  'post_id'		=> 'new_post',
    					  'field_groups'	=> array(431),
    					  'submit_value'		=> 'Submit',
    				));
    				?>
    				
    		  
    
    			<?php endwhile; ?>
    
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_footer(); ?>

    Here is my functions code (I’m assuming we’re about the functions.php in my theme):

    ///////////////////////////////////////////////
    // Form Processor
    ///////////////////////////////////////////////
    
    function pre_save_post( $post_id ) {
    	
    	// stop function if not a new post
    	if( $post_id !== 'new_post' ) {
    		return $post_id;
    	}
    	
    	// vars
    	$title = $_POST['fields']['field_577eeca76c4be'];
    	$dla = $_POST['fields']['field_577d8805fbf95'];
    	$miles = $_POST['fields']['field_577d9ddb09284'];
      	$service_member = $_POST['fields']['field_577d9e4e61f79'];
    	$deps_over_12 = $_POST['fields']['field_577da50b58664'];
      	$deps_under_12 = $_POST['fields']['field_577da57183151'];
    	$malt = $_POST['fields']['field_577da5d6049df'];
      
    	// Create a new post
    	$post = array(
    		'post_status'	=> 'publish',
    		'post_type'		=> 'pov_travel',
    		'post_title'	=> $title,
    	);	
    	
    
    	// insert the post
    	$post_id = wp_insert_post( $post ); 
    	
    	// return the new ID
    	return $post_id;
    	
    }

    The form renders on the frontend OK here: http://www.pcscalculator.com/mixed-mode/

    When I try to submit, the frontend appears to work but nothing is submitted to the custom post type.

    I can submit to this CPT from the backend with no problems. I have taken code snippets from https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/ and Leanne’s form https://support.advancedcustomfields.com/forums/topic/displaying-form-on-front-end-location-rules-issues/.

    My field group is set to only appear on post type pov travel.

    I’m running ACF 5 Pro.