I have created a CRED user form. On submission, I would like to redirect to a URL conditional on the selection of radio buttons.
This is the code I am using in my theme's functions.php:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id'] == 22651 ){ // this is my form ID
$url = '<em><u>hidden link</u></em>';
if ( $_REQUEST['wpcf-sub_type'] == 2 ){
$url = '<em><u>hidden link</u></em>';
}
}
return $url;
}
The problem is that the form does NOT redirect correctly (google.com) when the radio button value "2" is selected. The form redirects to bbc.co.uk regardless of which radio button is selected.
Hello. Thank you for contacting the Toolset support.
Well - the issue looks like here is that you are using wrong field name. For generic field - there is no need to prefix the field name with wpcf-
Could you please try to use following code - it should work.
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data)
{
if ($form_data['id'] == 22651 ){ // this is my form ID
$type = get_post_meta($post_id,'sub_type',true);
$url = '<em><u>hidden link</u></em>';
if ( $type == 2 ){
$url = '<em><u>hidden link</u></em>';
}
}
return $url;
}
I've tried your amended code, but the problem is still persisting, unfortunately. The form still redirects to hidden link even when the radio button, value ==2, is selected.
Could you please share problem URL where you added the form and access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
The thing is that you were using user forms so instead of get_post_meta() function we need to use get_user_meta() function.
I've adjust the code as given under:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data){
if ($form_data['id'] == 22651 ){ // this is my form ID
$type = get_user_meta($post_id,'sub_type',true);
$url = '<em><u>hidden link</u></em>';
if ( $type == 2 ){
$url = '<em><u>hidden link</u></em>';
}
}
return $url;
}
I can see its working fine. Could you please confirm.