Option Action

The Option Action is a template to create or update options on form submission.

Dynamic Form

Add actions on form submission

Click the "Add action" button below to start creating your layout
0 Custom action

Set a unique action slug

0 Email action
0 Option action

(Optional) Target this action using hooks.

Choose which ACF fields should be saved to this option

Fill inputs with values

Choose which ACF fields should have their values loaded

0 Post action

(Optional) Target this action using hooks.

Click to initialize TinyMCE

Choose which ACF fields should be saved to this post

Fill inputs with values

Choose which ACF fields should have their values loaded

0 Redirect action

(Optional) Target this action using hooks.

The URL to redirect to. See "Cheatsheet" tab for all available template tags.

0 Term action

(Optional) Target this action using hooks.

Click to initialize TinyMCE

Choose which ACF fields should be saved to this term

Fill inputs with values

Choose which ACF fields should have their values loaded

0 User action

(Optional) Target this action using hooks.

Click to initialize TinyMCE

Choose which ACF fields should be saved to this user

Fill inputs with values

Choose which ACF fields should have their values loaded

1 Option action

(Optional) Target this action using hooks.

Choose which ACF fields should be saved to this option

Fill inputs with values

Choose which ACF fields should have their values loaded

Option Settings

Setting nameDescription
Action nameAlias name allowing to use targeted hook
TargetThe options page to update
SourceThe options page to retrieve fields from
Load valuesFill inputs with values
Save ACF fieldsChoose which ACF fields should be saved to this options page
Load ACF fieldsChoose which ACF fields should have their values loaded

Validation

By default, there is no validation for this Action. You can use the acf/validate_value hook to validate each fields individually.

To validate the whole form, you can use the acfe/form/validation/option hook and throw errors with the acfe_add_validation_error() function. Usage example:

/*
 * Option Validation
 * 
 * @array   $form     Form settings
 * @string  $post_id  Post ID (where the form is displayed)
 * @string  $action   Action name
 */
 
action('acfe/form/validation/option',                  $form, $post_id, $action);
action('acfe/form/validation/option/form=my-form',     $form, $post_id, $action);
action('acfe/form/validation/option/action=my-option', $form, $post_id, $action);
add_action('acfe/form/validation/option/form=my-form', 'my_form_validation', 10, 3);
function my_form_validation($form, $post_id, $action){
    
    // 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');
        
    }
    
}

Prepare

The preparation phase is triggered after the form validation and before its submission. Returning false will stop the Action and go to the next one. Usage example:

/*
 * Option Prepare
 * 
 * @bool    $prepare  True/false
 * @array   $form     Form settings
 * @string  $post_id  Post ID (where the form is displayed)
 * @string  $action   Action name
 */
 
filter('acfe/form/prepare/option',                  $prepare, $form, $post_id, $action);
filter('acfe/form/prepare/option/form=my-form',     $prepare, $form, $post_id, $action);
filter('acfe/form/prepare/option/action=my-option', $prepare, $form, $post_id, $action);
add_filter('acfe/form/prepare/option/form=my-form', 'my_form_prepare', 10, 4);
function my_form_prepare($prepare, $form, $post_id, $action){
    
    // Stop the action if the user isn't logged in
    if(!is_user_logged_in()){
        
        $prepare = false;
        
    }
    
    // return
    return $prepare;
    
}

Values Source

Alter the option ID where meta values are loaded from. Usage example:

/*
 * Option Values Source
 * 
 * @int     $option_id  Option ID Source
 * @array   $form       Form settings
 * @string  $action     Action name
 */

filter('acfe/form/load/option_id',                  $option_id, $form, $action);
filter('acfe/form/load/option_id/form=my-form',     $option_id, $form, $action);
filter('acfe/form/load/option_id/action=my-option', $option_id, $form, $action);
add_filter('acfe/form/load/option_id/form=my-form', 'my_form_option_source', 10, 3);
function my_form_option_source($option_id, $form, $action){
    
    // Get field input value
    $my_field = get_field('my_field');
    
    if($my_field === 'Company'){
    
        // Force to load values from the Option Post ID 'my_options'
        $option_id = 'my_options';
    
    }
    
    // return
    return $option_id;
    
}

Option Target

Alter the option ID before database insert/update. Usage example:

/*
 * Option Arguments
 * 
 * @array   $option_id  Targeted Option Post ID
 * @array   $form       Form settings
 * @string  $action     Action name
 */

filter('acfe/form/submit/option_id',                  $option_id, $form, $action);
filter('acfe/form/submit/option_id/form=my-form',     $option_id, $form, $action);
filter('acfe/form/submit/option_id/action=my-option', $option_id, $form, $action);
add_filter('acfe/form/submit/option_id/form=my-form', 'my_form_option_id', 10, 3);
function my_form_option_id($option_id, $form, $action){
    
    /*
     * Get the form input value named 'my_field'
     */
    $my_field = get_field('my_field');

    if($my_field === 'Company'){
    
        // Change Option Post ID
        $option_id = 'my_options';
    
    }

    /*
     * Get previous Post Action output
     */
    $prev_post_action = acfe_form_get_action('post');
    
    if(!empty($prev_post_action)){
    
        if($prev_post_action['post_title'] === 'Company'){
    
            // Change Option Post ID
            $option_id = 'my_options';
            
        }

    }
    
    // So not save option
    // return false;
    
    // return
    return $option_id;
    
}

Submit

Trigger a custom action after the option was created/updated using the acfe/form/submit/option hook. Usage example:

/*
 * Option Submit
 * 
 * @int     $option_id  Targeted Option Post ID
 * @array   $form       Form settings
 * @string  $action     Action name
 */
 
action('acfe/form/submit/option',                  $option_id, $form, $action);
action('acfe/form/submit/option/form=my-form',     $option_id, $form, $action);
action('acfe/form/submit/option/action=my-option', $option_id, $form, $action);
add_action('acfe/form/submit/option/form=my-form', 'my_form_submit', 10, 3);
function my_form_submit($option_id, $form, $action){
    
    /*
     * Get the form input value named 'my_field'
     */
    $my_field = get_field('my_field');

    if($my_field === 'Company'){
    
        // do_something();
        
    }

    /*
     * Get previous Post Action output
     */
    $prev_post_action = acfe_form_get_action('post');
    
    if(!empty($prev_post_action)){
        
        if($prev_post_action['post_title'] === 'Company'){
            
            // do_something();
            
        }
        
    }
    
}