Support

Account

Home Forums General Issues Frontend Form not populating right in backend Reply To: Frontend Form not populating right in backend

  • Hi there,
    I apologize for the delay. The long weekend got away from me.

    Ok, here’s where I’m at right now. I’m not sure what I had before our last go-around and what’s been since, so here’s all of it.

    functions.php

    add_filter('acf/pre_save_post' , 'cmin_do_pre_save_post' );
    function cmin_do_pre_save_post( $post_id ) {
     
        // Bail if not logged in or not able to post
        if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
            return;
        }
     
        // check if this is to be a new post
        if( $post_id != 'new' ) {
            return $post_id;
        }
     
        // Create a new post
        $new_title_church_name = $_POST['acf']['field_577c12419eed1'];
    	
    	$new_title_date = get_field('start_date');
    	
    	// make date object
    	$new_title_date = new DateTime($new_title_date);
    	
    	$new_title = $new_title_church_name . ' - ' . $new_title_date->format('M j, Y');
    	
    	$new_slug = sanitize_title( $new_title );
        
        $post = array(
            'post_type'     => 'vbsform', // Your post type ( post, page, custom post type )
            'post_status'   => 'publish', // (publish, draft, private, etc.)
            'post_title'    => wp_strip_all_tags($new_slug), // Post Title ACF field key
            //'post_content'  => $_POST['acf']['field_54dfc94e35ec5'], // Post Content ACF field key
        );
     
        // insert the post
        $post_id = wp_insert_post( $post );
     
        // Save the fields to the post
        do_action( 'acf/save_post' , $post_id );
     
        return $post_id;
     
    }

    Form Page

    <?php
    
    function my_kses_post( $value ) {
    	// is array
    	if( is_array($value) ) {
    		return array_map('my_kses_post', $value);
    	}
    	// return
    	return wp_kses_post( $value );
    }
    
    add_filter('acf/update_value', 'my_kses_post', 10, 1);
    	
    add_action( 'get_header', 'cmin_do_acf_form_head', 1 );
    function cmin_do_acf_form_head() {
        // Bail if not logged in or not able to post
        if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
            return;
        }
        acf_form_head();
    }
    
    add_action( 'wp_print_styles', 'cmin_deregister_admin_styles', 999 );
    function cmin_deregister_admin_styles() {
        // Bail if not logged in or not able to post
        if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
            return;
        }
        wp_deregister_style( 'wp-admin' );
    }
     
    get_header(); ?>
    
    <div  class="page-wrapper">
    	<div class="row">
    		<div id="content" class="large-12 columns" role="main">
    			
    			<?php /* The loop */
    				if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
            echo '<p>You must be a registered author to post.</p>';
            return;
        }
        
        while ( have_posts() ) : the_post();
     
        $new_post = array(
            'post_id'            => 'new', // Create a new post
            // PUT IN YOUR OWN FIELD GROUP ID(s)
            'field_groups'       => array(2793), // Create post field group ID(s)
            'form'               => true,
            'return'             => '%post_url%', // Redirect to new post url
            'html_before_fields' => '',
            'html_after_fields'  => '',
            'submit_value'       => 'Submit VBS Event',
            'updated_message'    => 'Saved!'
        );
        acf_form( $new_post );
        
        endwhile; ?>
    
    		</div><!-- #content -->
    	</div><!-- #row -->
    </div><!-- #page-wrapper -->
    
    <?php acf_enqueue_uploader(); ?>
    
    <script type="text/javascript">
    (function($) {
    	
    	// setup fields
    	acf.do_action('append', $('#popup-id'));
    	
    })(jQuery);	
    </script>
    
    <?php get_footer(); ?>

    Most everything is working swimmingly, except I still cannot seem to get the start_date field to display in the title. It only displays the CURRENT date. Not sure why. I have the field date called. AND I once more have a pre-populated field, and I’m not sure why. I thought that had been solved previously, but it’s back. Grrrrrr