0

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?

flomei
  • 860
  • 1
  • 11
  • 36
abu
  • 41
  • 1
  • 3
  • 11

3 Answers3

1

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/') } "
Pawan Thakur
  • 591
  • 8
  • 19
0

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.

flomei
  • 860
  • 1
  • 11
  • 36
  • No. Stack Overflow is not about doing someones work, but helping to understand how to do it for yourself. – flomei Jun 29 '17 at 19:13
  • I have tried this code,but didn't get the solution. – abu Jun 29 '17 at 19:22
  • Yeah, that code does not work that way. And you put no effort in learning, so I´m out here. – flomei Jun 29 '17 at 20:22
0

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?

Purvik Dhorajiya
  • 4,662
  • 3
  • 34
  • 43
  • thank you for your suggestion, but i want to get the data in mail if filling and selecting the radio button as "Check". is this possible with the above code? – abu Jun 29 '17 at 17:16
  • @abu you haven't mention in your question. – Purvik Dhorajiya Jun 29 '17 at 17:28
  • i mean in first case the form is redirecting into PayPal(this time data not sending on mail) and in second case the form will send the data into desired email address as well as redirecting into a page some think like "Thank you". – abu Jun 29 '17 at 17:31
  • sorry @purvik7373, i forget to mention that. first case only redirection and in second case redirection as well as mail sending. – abu Jun 29 '17 at 17:32
  • i have tested the above code in my footer.php file inside the theme folder. but if selecting the Paypal option and clicking the submit button will showing the mail success message and received the mail .its not redirecting into paypal website. – abu Jun 29 '17 at 17:59
  • @abu have you enter this id `paypal-method` in your radio button? – Purvik Dhorajiya Jun 30 '17 at 04:13