Redirect Action

The Redirect Action is a template to create a redirection 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 Redirect action

(Optional) Target this action using hooks.

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

Redirect Settings

Setting nameDescription
Action nameAlias name allowing to use targeted hook
Action URLThe URL to redirect to.

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

/*
 * Redirect Validation
 * 
 * @array   $form     Form settings
 * @string  $post_id  Post ID (where the form is displayed)
 * @string  $action   Action name
 */
 
action('acfe/form/validation/redirect',                    $form, $post_id, $action);
action('acfe/form/validation/redirect/form=my-form',       $form, $post_id, $action);
action('acfe/form/validation/redirect/action=my-redirect', $form, $post_id, $action);
add_action('acfe/form/validation/redirect/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:

/*
 * Redirect 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/redirect',                    $prepare, $form, $post_id, $action);
filter('acfe/form/prepare/redirect/form=my-form',       $prepare, $form, $post_id, $action);
filter('acfe/form/prepare/redirect/action=my-redirect', $prepare, $form, $post_id, $action);
add_filter('acfe/form/prepare/redirect/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;
    
}

Redirect URL

Change the redirection URL. Usage example:

/*
 * Redirect URL
 * 
 * @array   $url     Redirect URL
 * @array   $form    Form settings
 * @string  $action  Action name
 */

filter('acfe/form/submit/redirect_url',                    $url, $form, $action);
filter('acfe/form/submit/redirect_url/form=my-form',       $url, $form, $action);
filter('acfe/form/submit/redirect_url/action=my-redirect', $url, $form, $action);
add_filter('acfe/form/submit/redirect_url/form=my-form', 'my_form_redirect_url', 10, 3);
function my_form_redirect_url($url, $form, $action){
    
    /*
     * Get the form input value named 'my_field'
     */
    $my_field = get_field('my_field');
    
    if($my_field === 'Company'){
        
        // Change Redirect URL
        $url = home_url('thank-you');
        
    }

    /*
     * 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 Redirect URL
            $url = home_url('thank-you');

        }
        
    }
    
    // Stop redirection
    // return false;
    
    // return
    return $url;
    
}