I am trying to: Setup a conditional redirect based upon a generic checkbox field. Here is what I currently am doing. I have all of my other fields in my form, but at the bottom I have a checkbox generic field. If the user doesn't check the box, it will submit the data and then go to the first URL, currently going to Google (plan to change to a generic thank you page). If the user checks the box the form will also submit the data, but go to a different URL.
I expected to see:
Instead, I got: Currently, the form is correctly setting the first URL, but I am unable to complete the IF conditional check on the value of the generic field. What am I doing wrong? I would like to add, that once I get this detection working I am wanting to also pass along some values as URL params concatenating them on the end of the second URL.
In Cred Form:
<label>Add An Additional Distributor</label>
[cred_generic_field type='checkbox' field='multi-dist']
{
"required":0,
"default":""
}
[/cred_generic_field]
In Functions:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data){
if ($form_data['id'] == 127515 ){ // this is my form ID
$type = get_post_meta($post_id,'multi-dist',true);
$url = '<em><u>hidden link</u></em>' ;
if ( $type == true ){
$url = '<em><u>hidden link</u></em>';
}
}
return $url;
}
Hi there,
Thank you for contacting us and I'd be happy to assist.
The generic field's value is not stored with regular custom field values, which is why it can't be called using the "get_post_meta" function.
You can check for its existence in the submitted data, through the global $_POST:
( ref: hidden link )
Example:
add_filter('cred_success_redirect', 'custom_redirect',10,3);
function custom_redirect($url, $post_id, $form_data){
if ($form_data['id'] == 127515 ){ // this is my form ID
$url = '<em><u>hidden link</u></em>' ;
if ( array_key_exists('multi-dist', $_POST) ){
$url = '<em><u>hidden link</u></em>';
}
}
return $url;
}
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
My issue is resolved now. Thank you!