Saltar navegación

[Resuelto] page refresh or redirect to custom url after form submit

This support ticket is created hace 5 años, 3 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Etiquetado: ,

Este tema contiene 8 respuestas, tiene 2 mensajes.

Última actualización por SteffenM1628 hace 5 años, 3 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#1332071
Bildschirmfoto 2019-09-05 um 08.00.02.png

Tell us what you are trying to do?

hey there, the title says it all. i need a simple page refresh after a form is submitted. or another solution to redirect to a custom url.
the options in the forms wizzard don´t have these options. (screenshot)

hope you can help me. i haven´t found any solutions in the forum.

cheers

#1332093

Hello,

I assume you are going to redirect user to some URL outsider the WordPress.

If it is, please try the filter hook "cred_success_redirect", see our document:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect

#1332353

Hey Luo,

the credhook is working. But i do have i problem because of the url attribute.

I need the redirect to the main url without
the parameter behind it
enlace oculto
Just need enlace oculto

Can we solve this with a javascript function maybe?

Thanks for your help

#1333049

For the new question:
Can we solve this with a javascript function maybe?

Unfortunate, since the the redirection is set in server side, so it can not be changed with javascript function, and the URL parameter "cred_referrer_form_id" is required to display form message, so there isn't any option to remove it.

#1333159

Hey Luo,

Thanks for your answer. I just checked the cred api. Maybe a walkourand would be possible with the cred_submit_complete function.
Maybe why can trigger here just a page refresh?

add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12)
    {
        // user can overwrite everything here, eg redirection, messages displayed etc..
        // eg redirect regardless of form settings
        header('location:success.php');
    }
}
 
//Custom success action can also be performed for a specific form by using the form ID:
add_action('cred_submit_complete_12', 'success_for_form_with_id_12',10,2);
function success_for_form_with_id_12($post_id, $form_data)
{
    //some code here
}

Sorry but i am a beginner to javascript but is it possible to trigger this

"document.location.reload(true)"

with the cred api?

#1333187

There is a simple workaround, you can try these:
1) Create a new wordpress page "my redirect endpoint", for example, page ID is 123

2) Edit your form, in the screenshot you mentioned above:
https://toolset.com/wp-content/uploads/2019/09/1332071-Bildschirmfoto_2019_09_05_um_08.00.02.png
Choose below options:
After visitors submit this form-> Go to a page...-> my redirect endpoint

So after user submit the form, it should be redirect to page "my redirect endpoint"

3) Modify the custom PHP codes as below, when user enter the page "my redirect endpoint", redirect him to the specific URL, for example:

add_action( 'template_redirect', function(){
	if(get_the_ID() == 123){
		header('Location: <em><u>enlace oculto</u></em>');
		exit;
	}
} );

More help:
https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect

#1334725

Hey luo, thanks for you help.
This workaround does work. But i noticed that it takes much more time with the redirect to another page and then redirect back.

Can‘t we use one of the cred apis to test if there is a better solution?
Maybe manipulate the url with the cred_form_action_uri_querystring_array
or the cred_submit_complete to overwrite the redirect and go direct to the home url.

Have a great start to the week

Cheers

#1334825

Yes, you are right, it is possible with action hook "cred_submit_complete" too, for example:

add_action('cred_submit_complete', 'my_success_action',10,2);
function my_success_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==123)
    {
        // user can overwrite everything here, eg redirection, messages displayed etc..
        // eg redirect regardless of form settings
        header('location:success.php');
        exit;
    }
}

Please replace 123 with your post form's ID

But it won't work if you use option "Submit this form without reloading the page (use AJAX)".

#1335541

My issue is resolved now. Thank you!