Click to initialize TinyMCE
Manage Advanced ACF Forms from the WordPress administration. This module is an enhanced version of the native ACF Form feature. While all native settings can used, Dynamic Forms adds many new settings and introduce “Actions” for a complete control over the form behavior.
The unique form slug
Render & map fields of the following field groups
Add actions on form submission
(Optional) Target this action using hooks.
The URL to redirect to. See "Cheatsheet" tab for all available template tags.
Apply field groups locations rules for front-end display
Whether or not to create a <form>
element
Form class and id
Add class to all fields
Whether or not to create a form submit button. Defaults to true
The text displayed on the submit button
HTML used to render the submit button loading spinner.
Whether to include a hidden input field to capture non human form submission. Defaults to true.
Whether or not to sanitize all $_POST data with the wp_kses_post() function. Defaults to true.
Whether to use the WP uploader or a basic input for image and file fields. Defaults to 'wp' Choices of 'wp' or 'basic'.
Determines element used to wrap a field. Defaults to 'div'
Determines where field labels are places in relation to fields. Defaults to 'top'.
Choices of 'top' (Above fields) or 'left' (Beside fields)
Determines where field instructions are places in relation to fields. Defaults to 'label'.
Choices of 'label' (Below labels) or 'field' (Below fields)
Override the native field groups HTML render
Extra HTML to add before the fields
Render your own customized HTML.
Field groups may be included using {field_group:group_key}
{field_group:Group title}
Fields may be included using {field:field_key}
{field:field_name}
Extra HTML to add after the fields
Choose where to display field errors
Add class to error message
Just like ACF Forms, first you need to create a Field Group that will contain the form’s fields. You can then create a new form from the ACF > Forms menu and assign that field group to the form. Once saved, the form will now map the Fields from the Field Group. This means those fields will be usable directly from the UI.
Out-of-the-box, the form will do nothing on submission. You’ll have to add one or multiple actions to define what you want to do with the form. Once correctly configured, you can display the form using acfe_form()
function or [acfe_form]
shortcode. Usage example:
<?php get_header(); ?>
<?php
// Using Form Name
acfe_form('my-form');
// Using Form ID
acfe_form(120);
// Using Form Array
acfe_form(array(
'name' => 'my-form'
));
?>
<?php get_footer(); ?>
You can override form settings directly in PHP by passing the setting key and its value.
acfe_form(array(
'name' => 'my-form', // Call by name
'acfe_form_uploader' => 'basic', // Force Uploader to basic
'acfe_form_html_submit_button' => '<button>Submit</button>' // Change Submit Button
));
It is possible to pass custom data to the form using PHP. Those data can then be retrieved in the UI using the {form:my_user}
Template Tag or in hooks using the $form['my_user']
parameter.
acfe_form(array(
'name' => 'my-form',
'my_user' => get_current_user_id() // Add Current User ID
));
Custom data can also be passed using the acfe/form/load
filter. Usage example:
add_filter('acfe/form/load/form=my-form', 'my_form_settings', 10, 2);
function my_form_settings($form, $post_id){
// Add Current User ID
$form['my_user'] = get_current_user_id();
// Return
return $form;
}
Templates Tags are UI helpers that retrieve & print dynamic content. There are different types of templates tags that retrieving different types of data.
Template Tag | Output |
{field:field_5e5c07b6dfae9} | User field input |
{field:my_field} | User field input |
{field:my_field:false} | User field input (unformatted) |
{fields} | My text: User input My textarea: User input My date: 2020-03-01 |
{get_field:my_field} | DB value (current post) |
{get_field:my_field:current} | DB value (current post) |
{get_field:my_field:128} | DB value (post:128) |
{get_field:my_field:128:false} | DB value (post:128 – unformatted) |
{get_option:my_option} | get_option('my_option') value |
{get_option:my_option:key} | get_option('my_option')['key'] value |
{request:name} | $_REQUEST['name'] value |
{request:name:key} | $_REQUEST['name']['key'] value |
{query_var:name} | get_query_var('name') value |
{query_var:name:key} | get_query_var('name')['key'] value |
{current:post} | Current Post ID |
{current:post:parameter} | Current Post parameter (such as post_title , post_content , post_date etc…) |
{current:term} | Current Term ID |
{current:term:parameter} | Current Term parameter (such as name , description etc…) |
{current:user} | Current User ID |
{current:user:parameter} | Current User parameter (such as user_login , user_email etc…) |
{current:author} | Current Post Author ID |
{current:author:parameter} | Current Post Author parameter (such as user_login , user_email etc…) |
{form} | Current Form ID |
{form:parameter} | Current Form parameter |
Dynamic Forms are bundled with general hooks allowing you to change the form settings, add validation rules and trigger a custom action on submission. Those hooks are tied to forms, and act independently from Actions.
Get Field
The get_field()
function used in form & actions hooks allows to retrieve the fields input that are entered by the user during the form submission. In order to retrieve the field value from the database, you must set a valid post ID reference.
Template Tag | Output |
get_field('my_field') | “my_field” Field input |
get_field('my_field', 128) | “my_field” DB value |
Loading Hook
The acfe/form/load
fitler is used to change the form settings, right before it is rendered on the page. Note that fields inputs cannot be retrieved using get_field()
here, as the form hasn’t been submitted yet. Usage example:
/*
* Form Load
*
* @array $form Form settings
* @string $post_id Post ID (where the form is displayed)
*/
filter('acfe/form/load', $form, $post_id);
filter('acfe/form/load/form=my-form', $form, $post_id);
add_filter('acfe/form/load/form=my-form', 'my_form_load', 10, 2);
function my_form_load($form, $post_id){
// Change form success message dynamically
$form['updated_message'] = 'New success message!';
// Change form redirection URL
$form['return'] = '/thank-you';
// Hide the form
// return false;
// Return
return $form;
}
Validation Hook
The acfe/form/validation
action is used to add rules during the ajax form validation process, before form submission.
Unlike the acf/validate_value
hook which validate each fields values individually, acfe/form/validation
will validate the whole form. It can be used to check one field against an another.
The acfe_add_validation_error()
function should be used to return an error. It is possible to return a general error by omitting to reference a field’s name. Example: acfe_add_validation_error('', 'General error message')
. Usage example:
/*
* Form Validation
*
* @array $form Form settings
* @string $post_id Post ID (where the form is displayed)
*/
action('acfe/form/validation', $form, $post_id);
action('acfe/form/validation/form=my-form', $form, $post_id);
add_action('acfe/form/validation/form=my-form', 'my_form_validation', 10, 2);
function my_form_validation($form, $post_id){
// Get field input value
$my_field = get_field('my_field');
if($my_field === 'Company'){
// Add validation error
acfe_add_validation_error('my_field', 'The value Company is not allowed');
}
}
Submission Hook
The acfe/form/submit
action is used to trigger a custom script on form submission, after its validation. Usage example:
/*
* Form Submit
*
* @array $form Form settings
* @string $post_id Post ID (where the form is displayed)
*/
action('acfe/form/submit', $form, $post_id);
action('acfe/form/submit/form=my-form', $form, $post_id);
add_action('acfe/form/submit/form=my-form', 'my_form_submit', 10, 2);
function my_form_submit($form, $post_id){
// Get field input value
$my_field = get_field('my_field');
if($my_field === 'Company'){
// Do something...
}
}
Actions are pre-defined templates that trigger a specific behavior. There can be an unlimited number of Actions per form. While every Actions have unique features like create a post, a user or send an e-mail, they also have their own validation
& submit
hooks.
Form Actions also have their own specific hooks that allow you to change their behavior. Learn more about Actions:
It is possible to export and import Forms in a Json file using the ACF > Tools menu or directly within the Dynamic Forms UI.
This module is enabled by default. To disable it, you can use the following code:
add_action('acf/init', 'my_acfe_modules');
function my_acfe_modules(){
// Disable Dynamic Forms
acfe_update_setting('modules/dynamic_forms', false);
// Or:
acf_update_setting('acfe/modules/dynamic_forms', false);
}