Hello,
A user chooses a sport during registration and then during connection he is redirected to an url in relation to the sport he has chosen.
Is it possible ? What would the code be?
Thank you.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Christophe,
Thank you for getting in touch.
We actually do have a redirect hook for the form completion action. You can find the reference document for it at the link below.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect
Here is an example usage below.
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==12)
$choice = types_render_usermeta( "my-checkboxes", array('item' => $post_id) );
if($choice == "A"){
return '<em><u>hidden link</u></em>';
}
if($choice == "B"){
return '<em><u>hidden link</u></em>';
}
return $url;
}
Please let me know if this helps.
Thanks,
Shane
Hello,
Here is my code but it doesn't work :
add_filter ('cred_success_redirect', 'custom_redirect', 10.3);
function custom_redirect ($ url, $ post_id, $ form_data)
{
if ($ form_data ['id'] == 3684)
$ choice = types_render_usermeta ("club", array ('item' => $ post_id));
if ($ choice == "1") {
return 'hidden link ';
}
if ($ choice == "2") {
return 'hidden link ';
}
return $ url;
}
Thank you
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi CHristophe,
Would you mind allowing me to have admin access to the site so that I can see what is wrong here?
I've enabled the private fields for your next response.
Also please let me know the page that you have the form on testing.
Thanks,
Shane
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Christophe,
Thank you for the credentials.
However where was the function added? I'm not seeing it at Toolset Custom Code.
Secondly I saw that you've disabled editing of the php files. Unfortunately without this I can't do much debugging on the code.
However I can advise you on how to test. This is a little extreme but it involves crashing the site, however we will be able to get what is being returned by the types_render_usermeta function.
Add this to your code.
This should dump out what is actually returned for the choice.
However you can also try getting the value directly from the POST request like this below.
add_filter ('cred_success_redirect', 'custom_redirect', 10.3);
function custom_redirect ($ url, $ post_id, $ form_data)
{
if ($ form_data ['id'] == 3684)
$ choice = $_POST['wpcf-club'];
if ($ choice == "1") {
return '<em><u>hidden link</u></em>';
}
if ($ choice == "2") {
return '<em><u>hidden link</u></em>';
}
return $ url;
}
Please try this and let me know the outcome of both.
Thanks,
Shane
you can now test in the toolset settings.
This is not working at the moment.
thank you.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Christophe,
This should now be working.
The problem was that you set the snippet to run on demand, however given that it is a hook it should always be running or listening for the redirect action.
Thanks,
Shane
It's OK !! Thank you
How to do the same with the wordpress login form ?
Thank you.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Christophe,
Are you using the default wordpress login form ?
If so then you can follow the instructions in the link below.
hidden link
Thanks,
Shane