Skip Navigation

[Resolved] Redirect connexion by user field

This support ticket is created 2 years, 10 months ago. 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Shane 2 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2096711

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.

#2097221

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

#2099181
test-toolset.jpg

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

#2099285

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

#2101365

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.

die($choice);

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

#2101991

you can now test in the toolset settings.
This is not working at the moment.

thank you.

#2102303

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

#2103119

It's OK !! Thank you

How to do the same with the wordpress login form ?

Thank you.

#2103137

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

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.