Redirect ActionFREE

Docs Modules Forms Actions Redirect

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

/**
 * Redirect Action: Validation
 * 
 * @array  $form    Form settings array
 * @array  $action  Action settings array
 */
 
action('acfe/form/validate_redirect',                    $form, $action);
action('acfe/form/validate_redirect/form=my-form',       $form, $action);
action('acfe/form/validate_redirect/action=my-redirect', $form, $action);
add_action('acfe/form/validate_redirect/form=my-form', 'my_redirect_validation', 10, 2);
function my_redirect_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:

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

#Redirect URL

Change the redirection URL. Usage example:

/**
 * Redirect Action: URL
 * 
 * @string  $url     Redirect URL
 * @array   $form    Form settings array
 * @array   $action  Action settings array
 *
 * @return string|false
 */

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_redirect_url', 10, 3);
function my_redirect_url($url, $form, $action){

    // get field input value
    $my_field = get_field('my_field');
    
    // check field value
    // and change redirect url
    if($my_field === 'Company'){
        $url = home_url('thank-you');
    }

    // get previous post action output (if any)
    // retrieve the 'permalink' specifically
    $post_permalink = acfe_get_form_action('post.permalink');
    
    // check the permalink exists
    // and use it as redirect url
    if($post_permalink){
        $url = home_url($post_permalink);
    }

    // do not redirect
    // return false;
    
    // return normally
    return $url;
    
}