Click to initialize TinyMCE
The Redirect Action is a template to create a redirection on form submission.
Add actions on form submission
(Optional) Target this action using hooks.
The URL to redirect to. See "Cheatsheet" tab for all available template tags.
(Optional) Target this action using hooks.
Fill inputs with values
(Optional) Target this action using hooks.
The URL to redirect to. See "Cheatsheet" tab for all available template tags.
Setting name | Description |
Action name | Alias name allowing to use targeted hook |
Action URL | The URL to redirect to. |
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');
}
}
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; }
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;
}