Pass this ticket to Waqar, *unless you can offer a valuable solution step-by-step before Waqar comes back from vacation this friday*.
Hi Waqar,
On this page hidden link we have a 'select field' 'Ik wil het aanbod gratis bekijken'.
Now, we want 3 things:
1. We want to redirect users to a different page after submitting based on whether or not the field is selected.
2. We want to send a different notification email after submitting based on whether or not the field is selected.
For example 1 and 2:
If field 'Ik wil het aanbod gratis bekijken' is selected, the submit button goes to page A and notification A is sent to the user & admin.
If field 'Ik wil het aanbod gratis bekijken' is not selected, the submit button goes to page B and notification B is sent to the user & admin.
3. In the form we have a conditional with below fields that are required:
'Ik heb'
'straatnaam'
'huisnummer'
'woonplaats'
We want the above required fields to be 'mandatory' if the field 'Ik wil het aanbod gratis bekijken' is selected.
If the field 'Ik wil het aanbod gratis bekijken' is not selected the required fields should 'not' be mandatory.
New threads created by Waqar and linked to this one are listed below:
For example, the ID of the user form in question is "18888" and suppose that if that field is checked, you'd like to redirect to the page with ID "123" and if unchecked, redirect to the page with ID "456". The code in this case would look like this:
add_filter('cred_success_redirect', 'custom_redirect_user_form_18888',10,3);
function custom_redirect_user_form_18888($url, $post_id, $form_data)
{
// process only if specific form
if ($form_data['id']==18888) {
// ID of the page to redirect to when the field is checked
$checked_paged_id = 123;
// ID of the page to redirect to when the field is not checked
$unchecked_paged_id = 456;
// check if the field is checked
if(isset($_POST['wpcf-ik-wil-het-aanbod-gratis-bekijken'][0])) {
return get_post_permalink( $checked_paged_id );
}
else
{
return get_post_permalink( $unchecked_paged_id );
}
}
return $url;
}
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/
For the other two questions, I've created separate tickets and will reply to them shortly.
We have setup the below custom code called "custom registration confirmation", HOWEVER we are not getting redirected accordingly to:
1. hidden link IF user did NOT check "Ik wil het aanbod gratis bekijken".
OR
2. hidden link IF user did check "Ik wil het aanbod gratis bekijken".
Instead users stay on the form page (see attachment).
For the form we applied: Go to "Bedankt om in te schrijven!" (see attachment). We can only add 1 page here. I don't think this makes sense as we want to redirect users based on the checkbox.
What is wrong here?
Please test everything from your side.
add_filter('cred_success_redirect', 'custom_redirect_user_form_18888',10,3);
function custom_redirect_user_form_18888($url, $post_id, $form_data)
{
// process only if specific form
if ($form_data['id']==18888) {
// ID of the page to redirect to when the field is checked
$checked_paged_id = 19006;
// ID of the page to redirect to when the field is not checked
$unchecked_paged_id = 672;
// check if the field is checked
if(isset($_POST['wpcf-ik-wil-het-aanbod-gratis-bekijken'][0])) {
return get_post_permalink( $checked_paged_id );
}
else
{
return get_post_permalink( $unchecked_paged_id );
}
}
return $url;
}
When I checked your form "Nieuwe gebruiker registreren DEFINITIEF" earlier, it was set to redirect to a page after submission.
But, now that setting was changed and the form was set to keep displaying, which is why the custom code attached to the "cred_success_redirect" hook was not working. I've changed that setting to redirect to a page and the redirection code is working now.
Note: It doesn't matter which page is selected for redirection in the form's settings, as the actual page for redirection will be selected by the custom code.