Home › Forums › General Issues › Frontend Form not populating right in backend › Reply To: Frontend Form not populating right in backend
I’m feeling pretty dense right about now. Honestly, I’m trying to get this figured out, and have looked at the links you’ve sent and tried a ridiculous number of combinations of things. But now the title isn’t working at all.
I removed the section from functions that you said was no longer necessary. Replaced it with what’s below.
The new title shows properly in the body of the resulting post page, but it isn’t reflected as either the title or the slug. So, for instance, the latest new post from this form resulted in a slug of “vbsform/3024-2/”, instead of “vbsform/title-start_date/”
Functions.php
//Auto add and update Title field:
function vbs_post_title_updater( $post_id ) {
// get the church name
$new_title_church_name = get_field('church_name', $post_id);
// get the selected date and the current date
$new_title_date = get_field('start_date', $post_id);
$new_title_date = new DateTime($new_title_date);
// set the title
$new_title = $new_title_church_name . ' - ' . $new_title_date->format('M j, Y');
// create the update data holder
$vbs_post = array();
$vbs_post['ID'] = $post_id;
$vbs_post['title'] = $new_title;
//Unhook function to prevent infitnite looping
remove_action('acf/save_post', 'vbs_post_title_updater', 20);
//Rehook function to prevent infitnite looping
add_filter('acf/save_post', 'vbs_post_title_updater', 20);
}
// run after ACF saves the $_POST['fields'] data
add_action('acf/save_post', 'vbs_post_title_updater', 20);
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;
}
$vbs_post = array(
'post_id' => 'new_post',
'post_title' => wp_strip_all_tags($new_title),
'post_content' => false,
'form' => true,
'new_post' => array(
'post_type' => 'vbsform',
'post_status' => 'publish'
),
'field_groups' => array(2793),
'return' => '%post_url%',
'submit_value' => 'Submit VBS Event',
'updated_message' => 'Saved!',
'post_title' => wp_strip_all_tags($new_slug),
);
acf_form( $vbs_post );
</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(); ?>
Results 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();
}
get_header();
?>
<?php
// Create big featured image if set
if($flatsome_opt['blog_post_style'] == 'big-featured-image') { ?>
<div class="parallax-title">
<?php while ( have_posts() ) : the_post(); ?>
<?php ob_start(); ?>
<header class="entry-header text-center">
<div class="tx-div small"></div>
<?php if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php the_date('F j, Y', 'Submitted on ', ''); ?>
</div>
</header>
<?php endwhile; // end of the loop. ?>
</div>
<?php } ?>
<div class="page-wrapper page-<?php echo $flatsome_opt['blog_post_layout']; ?>">
<div class="row">
<div class="page-inner">
<?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;
} ?>
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if($flatsome_opt['blog_post_style'] == 'default' || !isset($flatsome_opt['blog_post_style'])) { ?>
<header class="entry-header text-center">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="tx-div small"></div>
<div class="entry-meta">
<?php the_date('F j, Y', 'Submitted on ', ''); ?> by <?php the_author(); ?><br>
This post was last modified by <?php the_modified_author(); ?> on <?php the_modified_date('F j, Y'); ?> at <?php the_modified_date('g:i a'); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<?php $author_id = get_the_author_meta('ID');
$author_phone = get_field('phone_number', 'user_'. $author_id );
$term = get_field('conference');
$start_date = get_field('start_date', false, false);
$start_date = new DateTime($start_date);
$end_date = get_field('end_date', false, false);
$end_date = new DateTime($end_date);
$images = get_field('images');
?>
<table class="table table-striped">
<tr>
<td>Church Name</td>
<td><?php the_field('church_name'); ?> Adventist Church</td>
</tr>
<?php if( $term ): ?>
<tr>
<td>Conference</td>
<td><?php echo $term->name; ?></td>
</tr>
<?php endif; ?>
<tr>
<td>Contact Person</td>
<td><?php the_author(); ?></td>
</tr>
<tr>
<td>E-mail address</td>
<td><?php the_author_meta('user_email'); ?></td>
</tr>
<tr>
<td>Phone Number</td>
<td><?php echo $author_phone; ?></td>
</tr>
<tr>
<td>I am the...</td>
<td><?php the_field('i_am'); ?></td>
</tr>
<tr>
<td>Start Date</td>
<td><?php echo $start_date->format('F j, Y'); ?></td>
</tr>
<tr>
<td>End Date</td>
<td><?php echo $end_date->format('F j, Y'); ?></td>
</tr>
<?php if( $images ) { ?>
<tr>
<td>Images</td>
<td>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<a href="<?php echo $image['url']; ?>">
<img src="<?php echo $image['sizes']['admin-thumb']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
</li>
<?php endforeach; ?>
</ul>
</td>
</tr>
<?php } ?>
</table>
<div class="edit-form">Edit this VBS submission</div>
<div class="vbs-off"><?php acf_form(); ?></div>
</div><!-- .entry-content -->
<script>
$ = jQuery;
$(".edit-form").click(function(){
$(".vbs-off").toggleClass("vbs-on");
$(this).toggleClass("vbs-on");
}, function() {
$(".vbs-off").toggleClass("vbs-on");
});
</script>
</article>
<?php endwhile; // end of the loop. ?>
</div><!-- .page-inner -->
</div><!-- #content -->
<div class="large-3 columns left">
<?php get_sidebar(); }?>
</div><!-- end sidebar -->
</div><!-- end row -->
</div><!-- end page-wrapper -->
<?php acf_enqueue_uploader(); ?>
<script type="text/javascript">
(function($) {
// setup fields
acf.do_action('append', $('#popup-id'));
})(jQuery);
</script>
<?php get_footer(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.