Support

Account

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

Solved

Blank page when front end form is submited

  • Hi,

    I’m building a WP theme that uses ACF 4.3.8 to allow users to post from the front end (with php exported fields in functions.php). Although my theme is working fine on my local wamp instalation, when I try to use it on a fresh live wordpress installation I get a blank page whenever I try to post. If I go back and refresh, the new post will be there so it’s kind of working if it wasn’t for this blank page after posting… Editing the post via front end seems to work fine but it also displays some warnings/notices in debug mode (I’ll go into more detail on this below).

    With debug mode activated I get the following errors when…

    submitting a new post:

    Warning: array_filter() expects parameter 1 to be array, string given in /home/…mywpsite/wp-includes/post.php on line 2983

    Warning: Cannot modify header information – headers already sent by (output started at /home/… /mywpsite/wp-includes/post.php:2983) in /home/ … /mywpsite/wp-includes/pluggable.php on line 1121

    editing existing post:

    Notice: Undefined index: ID in /home … /mywpsite/wp-includes/post.php on line 3284

    Warning: Cannot modify header information – headers already sent by (output started at /home/ … /mywpsite/wp-includes/post.php:3284) in /home/ … /mywpsite/wp-includes/pluggable.php on line 1121

    I’m using wordpress version 3.9.1

    Any help would be greatly appreciated

  • 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,
    			),
    ...
  • sorted now, just needed to read what the errors had to say… 🙂

  • How did you end up fixing this? I have the same problem, Blank page (with same address) when the form is submitted, however it still goes through.

  • not sure which errors you’re getting but in your pre_save_post function make sure your category value is within an array:

    'post_category'=> array($_POST['fields']['field_53b4955981c40']),

    and also if you’re editing the post you need to refer to the post ID:

    'ID' => $post_id,

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.