Support

Account

Home Forums General Issues Blank page when front end form is submited Reply To: Blank page when front end form is submited

  • Ok so I’ve managed to isolate the problem to a categories field in my fron end form (the user gets to choose which category the post should go into). If the user leaves it as ‘none'(null) there are no errors but if a category is chosen the submitting errors above are displayed. I can’t test this for editing the post because I’m also having this issue: http://support.advancedcustomfields.com/forums/topic/when-selecting-taxonomy-acf-fields-disappear/#post-15118

    I’ve added a bit more info on the code I’m using below as I’m probably doing something wrong…

    Would greatly appreciate any help with this

    my form for submiting:

    <?php 
        $args = array(
            'post_id' => 'new',
    		'field_groups' => array( 'acf_add_post' ),			
    		'submit_value' => 'Add Post',
    		'return' => add_query_arg( 'updated', 'true', get_site_url()),// return url
    		);     
        acf_form( $args ); 
    ?>

    my form for editing:

    <?php
    	$args = array(
    		'post_id' => $post->ID,
    		'field_groups' => array( 'acf_add_post' ), 			
    		'submit_value' => 'Edit Post',
    		'return' => add_query_arg( 'updated', 'true', get_permalink() ),// return url
    	);     
        acf_form( $args ); 
    ?>

    my pre_save_post function:

    function my_pre_save_post( $post_id ){
        
    	// Create the post
    	$post = array(
    		'post_status'  => 'publish' ,
    		'post_title'  =>  $_POST['fields']['field_53701ca623c65'],				
    		'post_content' => $_POST['fields']['field_53701c4623c64'],				
    		'post_category'	=> $_POST['fields']['field_53b4955981c40'],
    		'post_type'  => 'post'
        ); 
    	
    	if( $post_id != 'new' )	{	// check if this is to be an edit instead of a new post	
        	
            $post_id = wp_update_post( $post ); // update the post 		
        }
    	else {  
        
    		$post_id = wp_insert_post( $post ); // insert the post
    	}
      
        return $post_id;						// return the post (new or edited)
    }
      
    add_filter('acf/pre_save_post' , 'my_pre_save_post' );

    my exported php:

    include_once('advanced-custom-fields/acf.php');
    
    //Register ACF fields
    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_add_post',
    		'title' => 'Add_post',
    		'fields' => array (
    			array (
    				'key' => 'field_53701ca623c65',
    				'label' => 'Title',
    				'name' => 'title',
    				'type' => 'text',
    				'required' => 1,
    				'default_value' => '',
    				'placeholder' => 'Title',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => 50,
    			),
    			array (
    				'key' => 'field_537e8061c8a97',
    				'label' => 'Description',
    				'name' => 'description',
    				'type' => 'text',
    				'default_value' => '',
    				'placeholder' => 'what\'s your post about?',
    				'prepend' => '',
    				'append' => '',
    				'formatting' => 'html',
    				'maxlength' => 100,
    			),
    			array (
    				'key' => 'field_53b4955981c40',
    				'label' => 'Category',
    				'name' => 'category',
    				'type' => 'taxonomy',
    				'taxonomy' => 'category',
    				'field_type' => 'select',
    				'allow_null' => 1,
    				'load_save_terms' => 1,
    				'return_format' => 'object',
    				'multiple' => 0,
    			),
    ...