Custom Action

The Custom Action is a canvas for developers that want to trigger a custom script on form submission. Out-of-the-box, this action will do nothing 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.

Fill inputs with values

0 Post action

(Optional) Target this action using hooks.

Click to initialize TinyMCE

Fill inputs with values

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

Fill inputs with values

0 User action

(Optional) Target this action using hooks.

Click to initialize TinyMCE

Fill inputs with values

1 Custom action

Set a unique action slug.

Action Settings

Setting nameDescription
Action nameAlias name allowing to use targeted hook. It cannot be named custom, email, post or term.

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/validate_my-action hook and throw errors with the acfe_add_validation_error() function. Usage example:

/**
 * Custom Action: Validation
 * 
 * @array  $form    Form settings array
 * @array  $action  Action settings array
 */
 
action('acfe/form/validate_my-action',              $form, $action);
action('acfe/form/validate_my-action/form=my-form', $form, $action);
add_action('acfe/form/validate_my-action', 'my_form_validation', 10, 2);
function my_form_validation($form, $action){

    // get current post id
    // where the form is displayed
    $post_id = $form['post_id'];
    
    // get field input value
    $my_field = get_field('my_field');
    
    // check field value
    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:

/**
 * Custom Action: Prepare
 * 
 * @array  $action  Action settings array
 * @array  $form    Form settings array
 *
 * @return array|false
 */
 
filter('acfe/form/prepare_my-action',              $action, $form);
filter('acfe/form/prepare_my-action/form=my-form', $action, $form);
add_filter('acfe/form/prepare_my-action', 'my_form_prepare', 10, 2);
function my_form_prepare($action, $form){
    
    // if user isn't logged in
    // do not submit the action
    if(!is_user_logged_in()){
        return false;
    }
    
    // return normally
    return $action;
    
}

Submit

Trigger a custom submission action using the acfe/form/submit_my-action hook. Usage example:

/**
 * Custom Action: Submit
 * 
 * @array  $form    Form settings array
 * @array  $action  Action settings array
 */
 
action('acfe/form/submit_my-action',              $form, $action);
action('acfe/form/submit_my-action/form=my-form', $form, $action);
add_action('acfe/form/submit_my-action', 'my_form_submit', 10, 2);
function my_form_submit($form, $action){

    // get current post id
    // where the form is displayed
    $post_id = $form['post_id'];
    
    // get field input value
    $my_field = get_field('my_field');

    // check field value
    if($my_field === 'Company'){
        // do something
    }

    // get previous post action output (if any)
    $post_action = acfe_form_get_action('post');
    
    // check previous post action exists
    if(!empty($post_action)){
    
        // get the post title of the created post
        if($post_action['post_title'] === 'Post Title'){
            // do something
        }

    }
    
}