I needed to create a form that redirects the user to separate PayPal accounts depending on selection criteria in the form. In this case, a radio button.
Fortunately, Contact Form 7 has a nice little feature (action hook) called: on_sent_ok
This action hook will allow you to execute javascript code once the form email is sent. The full syntax is: on_sent_ok: “your_javascript_here”
I am not absolutely certain about this, but I believe what is between the quotes can only be one line of code. This line of code must go in the ‘Additional Settings’ section of the contact form.
So……..in my case, in order to redirect, I execute a function: on_sent_ok: “paypalRedirect();”
Now….on the page where the contact form is located, add:
<script> function paypalRedirect() { if (document.getElementsByName("your_radio")[0].checked) { location.href = 'http://www.paypal.com/link1'; } else { location.href = 'http://www.paypal.com/link2'; } } </script>
If you prefer to use getElementById instead of getElementsByName, you will need to use the ‘id:idvalue’ parameter when defining your Contact Form 7 fields. I actually recommend using getElementById and the ‘id:’ parameter for greater control over your form.