acf_form_head()ACF 5.0.0

Used to process, validate, and save data submitted by a form created with acf_form(). The function also enqueues the form scripts and styles required for correct display.

Call it before outputting any HTML. It is recommended to call it before get_header().

No Hooks.

Returns

null.

Usage

acf_form_head();

Examples

#1 Template integration example

This example demonstrates the basic acf_form() function used to edit the viewed post.

<?php acf_form_head(); ?>
<?php get_header(); ?>

	<div id="primary" class="content-area">
		<div id="content" class="site-content" role="main">
			<?php acf_form(); ?>
		</div>
	</div>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Actions and filters

The following hooks (actions and filters) allow form-data processing to be changed.

acf/pre_submit_form

Runs after the form is submitted and before the data is saved. Use this filter to modify the $form array before saving $_POST data.

add_filter( 'acf/pre_submit_form', 'my_acf_pre_submit_form', 10, 1 );
function my_acf_pre_submit_form( $form ) {
	// Create post using $form['new_post'].
	// Modify $form['redirect'].
	return $form;
}
acf/pre_save_post

Runs after the acf/pre_submit_form filter and before the data is saved. Use this filter to modify the $post_id value before saving $_POST data.

add_filter( 'acf/pre_save_post', 'my_acf_pre_save_post', 10, 2 );
function my_acf_pre_save_post( $post_id, $form ) {
	// Create post using $form and update $post_id.
	return $post_id;
}
acf/save_post

Runs after ACF $_POST data is saved.

add_action( 'acf/save_post', 'my_acf_save_post', 20 );
function my_acf_save_post( $post_id ) {

	// Get new value.
	$value = get_field('my_field', $post_id);

	// Do something.
}
acf/submit_form

Runs after $_POST data is saved. Use this action to perform custom logic before using the return parameter to redirect the browser.

add_action( 'acf/submit_form', 'my_acf_submit_form', 10, 2 );
function my_acf_submit_form( $form, $post_id ) {

	// Get new value.
	$value = get_field('my_field', $post_id);

	// Redirect.
	wp_redirect( 'http://www.website.com/' . $value );
	exit;
}

Changelog

Since 5.0.0 Introduced.

acf_form_head() code ACF 6.8.8

function acf_form_head() {

	acf()->form_front->enqueue_form();
}