Although redirecting your form to a thank you page is not necessary in most cases, it might make sense to do this sometimes.
Redirect without submitting the form
If you just want to use the form to redirect someone to another page without actually submitting the form, you could just add some links in the groups and style them as buttons.
Form
Form Code
[radio redirect use_label_element "redirect to google.com" "redirect to example.com"]
[group google]<a class="btn" href="https://google.com">Go to Google</a>[/group]
[group example]<a class="btn" href="https://example.com">Go to Example</a>[/group]
Conditional Fields (Text)
show [google] if [redirect] equals "redirect to google.com"
show [example] if [redirect] equals "redirect to example.com"
Edit this form in the form tester
Redirect after submitting the form
If you do need to process the form and additionally redirect conditionally, you could write your form like this:
[radio redirect use_label_element "redirect to google.com" "redirect to example.com"]
[group google][submit "Submit and redirect to Google"][/group]
[group example][submit "Submit and redirect to example"][/group]
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
if(jQuery('[data-id="google"]').is(':visible')) {
location = 'https://google.com'
} else if (jQuery('[data-id=example]').is(':visible')) {
location = 'http://example.com/';
}
}, false );
</script>
Form
Form Code
<p><strong>Note:</strong> because this example form does not actually send out any emails, the redirect is triggered by listening to the <code>wpcf7mailfailed</code> event. If you want to use this code on your own website, you need to change this to <code>wpcf7mailsent</code> instead.</p>
[radio redirect use_label_element "redirect to google.com" "redirect to example.com"]
[group google][submit "Submit and redirect to Google"][/group]
[group example][submit "Submit and redirect to example"][/group]
<script>
document.addEventListener( 'wpcf7mailfailed', function( event ) {
if(jQuery('[data-id="google"]').is(':visible')) {
location = 'https://google.com'
} else if (jQuery('[data-id=example]').is(':visible')) {
location = 'http://example.com/';
}
}, false );
</script>
Conditional Fields (Text)
show [google] if [redirect] equals "redirect to google.com"
show [example] if [redirect] equals "redirect to example.com"