Skip Navigation

[Resolved] Detecting a Generic Field Checkbox on submit for a Conditional Redirect URL

This support ticket is created 5 years, 5 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 – 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/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by aprilA 5 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1320543

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;
}
#1320987

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

#1321215

My issue is resolved now. Thank you!