abu
abu

Reputation: 51

Redirect to URL, specified by form value, on submit of Contact Form 7

I have created a form using the Contact Form 7 plugin for WordPress.

My form looks like this:

<label> Your Name (required)
[text* your-name] </label>

<label> Your Email  (required)
[email* email]</label>

<label> Payment Method
[radio payment default:1 "Paypal" "Check"] </label>

[submit "Send"]

If someone is filling out the form and selects the payment method "PayPal" and clicks the "Send" button I want to redirect him to the PayPal website (just a PayPal URL).

If someone is selecting the payment method "Check" and clicks to submit them form, it will redirect him to a "Thank you" page.

How can I achieve this, when using the Contact Form 7 plugin?

Upvotes: 0

Views: 3156

Answers (3)

Pawan Thakur
Pawan Thakur

Reputation: 591

Add following code to Additional Settings, but change id and value according to your requirement:

on_sent_ok: " if (document.getElementById('car').value=='yes') {location.replace('http://www.redirectedpage1.com')} else { location.replace('http://www.redirectedpage2.com/') } "

Upvotes: 1

Purvik Dhorajiya
Purvik Dhorajiya

Reputation: 4880

Contact form 7 redirect based on radio button value.

<script>
jQuery(document).ready(function($){
    $(".wpcf7").on( 'mailsent.wpcf7', function(){
        var redirect_to = $(this).find('#paypal-method').val();  // Enter your radio button id
        if( typeof(redirect_to)!=='undefined' && redirect_to!='' ){
            if( redirect_to == 'Paypal' ){
                window.location.href= "https://www.paypal.com/";
            }elseif( redirect_to == 'Check' ){
                window.location.href= "https://www.example.com/";
            }

        }
    });
});
</script>

Would you please try above code?

Upvotes: 0

flomei
flomei

Reputation: 880

You could add a hook which is triggered when the form has been submitted but before the mail has been sent. This question on WP:SE has several answers on that.

When you have yourself hooked into the process, you will have access to the content of the submitted form and therefore access to the chosen Payment method.

You can check the selected value and make a redirect based on that. wp_redirect could come in handy here.

Upvotes: 0

Related Questions