Title: [Plugin: Contact Form 7] Conditional Redirect?
Last modified: August 19, 2016

---

# [Plugin: Contact Form 7] Conditional Redirect?

 *  Resolved [ckpicker](https://wordpress.org/support/users/ckpicker/)
 * (@ckpicker)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/)
 * I’m currently using the on_sent_ok action hook in my ‘additional settings’ to
   redirect a form to a thank you page.
 * I would like to modify this to redirect them to a different page depending on
   which value they selected in a drop-down field (with ID ‘technicians’) on the
   form.
 * Is it possible to do something like this maybe with jQuery? I was trying to do
   this:
 * on_sent_ok: “alert(‘Technician ‘ + $(“#technicians”).val());”
 * But keep receiving a NULL value. Any ideas?

Viewing 14 replies - 1 through 14 (of 14 total)

 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663332)
 * Yes. Try
 * > on_sent_ok: “alert(‘Technician ‘ + jQuery(‘#technicians’).val());”
 *  Thread Starter [ckpicker](https://wordpress.org/support/users/ckpicker/)
 * (@ckpicker)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663334)
 * Nope. The value just keeps coming back as ‘null’.
 *  Thread Starter [ckpicker](https://wordpress.org/support/users/ckpicker/)
 * (@ckpicker)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663342)
 * I even tried to do it the “old school” JavaScript way:
 * `on_sent_ok: "alert('Technician ' + document.forms[1].technicians.options[document.
   forms[1].technicians.selectedIndex].value);"`
 * But nothing happens. No alert box or anything. What am I doing wrong?
 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663371)
 * No one can verify it if you don’t tell the URL of the page.
 *  Thread Starter [ckpicker](https://wordpress.org/support/users/ckpicker/)
 * (@ckpicker)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663376)
 * Here it is:
 * [http://www.remcosolutions.com/customers/give-us-your-feedback/](http://www.remcosolutions.com/customers/give-us-your-feedback/)
 * The password is 0807.
 *  Plugin Author [Takayuki Miyoshi](https://wordpress.org/support/users/takayukister/)
 * (@takayukister)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663393)
 * Sorry, I missed an important thing. In current implementation, when submission
   is completed, Contact Form 7 once resets and clears the form, then runs the on_sent_ok
   hook. So no values remain at that moment.
 * To make it work, you will need to modify scripts.js file as:
 * Before
 *     ```
       if (1 == data.mailSent) {
       		jQuery(data.into).find('form').resetForm().clearForm();
       		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
   
       		if (data.onSentOk)
       			jQuery.each(data.onSentOk, function(i, n) { eval(n) });
       	} else {
       ```
   
 * After
 *     ```
       if (1 == data.mailSent) {
       		if (data.onSentOk)
       			jQuery.each(data.onSentOk, function(i, n) { eval(n) });
   
       		jQuery(data.into).find('form').resetForm().clearForm();
       		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
       	} else {
       ```
   
 * I hope this can help.
 *  Thread Starter [ckpicker](https://wordpress.org/support/users/ckpicker/)
 * (@ckpicker)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663396)
 * That did the trick!! Thanks so much!
 *  [cporichie](https://wordpress.org/support/users/cporichie/)
 * (@cporichie)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663478)
 * Can I have some help with this. I understand the concept but am not a java coder
   really. I want to redirect to two different pages based on a condition in the
   form.
 * If check box A, website A, else website B.
 * Thanks for any help. By the way when I try the alert
 * I get the box, but no text at all from the jQuery part of this:
    on_sent_ok: “
   alert(‘Sign ‘ + jQuery(‘#Sign’).val());”
 * this is my checkbox:
    [checkbox checkbox-Sign id:Sign “text | yes”
 *  [amitkatoch](https://wordpress.org/support/users/amitkatoch/)
 * (@amitkatoch)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663561)
 * If you want to get radio button value of the contact 7 form. you can use the 
   below code:
 * `on_sent_ok: "alert('jQuery('form input[type=radio]:checked').val());"`
 *  [manku.patel](https://wordpress.org/support/users/mankupatel/)
 * (@mankupatel)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663581)
 * i have same problem with this radio button..popup appears without any value
 * this is my radio button
    [radio offer id:offer “Yes”][radio offer id:offer “No”]
 * N.B: I have tried your idea amitkatoch but it won’t work
 * thnks:)
 *  [manku.patel](https://wordpress.org/support/users/mankupatel/)
 * (@mankupatel)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663582)
 * i am done with all the above ideas……plz guys help me…
 *  [suso](https://wordpress.org/support/users/suso/)
 * (@suso)
 * [15 years ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663599)
 * This is just what i need!! but not a pop-up!! i need to redirect to page A if
   A, else page B…
 *  [naturalworth](https://wordpress.org/support/users/naturalworth/)
 * (@naturalworth)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663600)
 * Hey ckpicker and Takayuki Miyoshi the information you’ve shared is very helpful.
   Thanks.
 * I think I’m a step or two from successfully using the on_sent_ok action hook 
   in my ‘additional settings’ to redirect a forms to a different page depending
   on which value is selected in a drop-down field.
 * I modified the scripts.js file replacing line 48;
 *     ```
       if (1 == data.mailSent) {
       $(data.into).find('form').resetForm().clearForm();		ro.addClass('wpcf7-mail-sent-ok');
            if (data.onSentOk) $.each(data.onSentOk, function(i, n) { eval(n) });	} else {
       ```
   
 * with the code Takayuki Miyoshi provided.
 *     ```
       if (1 == data.mailSent) {
       		jQuery(data.into).find('form').resetForm().clearForm();
       		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
   
       		if (data.onSentOk)
       			jQuery.each(data.onSentOk, function(i, n) { eval(n) });
       	} else {if (1 == data.mailSent) {
       		if (data.onSentOk)
       			jQuery.each(data.onSentOk, function(i, n) { eval(n) });
   
       		jQuery(data.into).find('form').resetForm().clearForm();
       		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
       	} else {
       ```
   
 * The good news is I don’t receive the Null value any more when send is clicked.
 * The bad news is when send is click it does not redirecting to the page I want
   it to go to. It comes back to the form page.
 * I think the problem maybe something basic Maybe I’m not using custom fields correctly.
 * This is the site. [http://www.emekayoga.com/?page_id=11](http://www.emekayoga.com/?page_id=11)
 * This is the code I put in my Contact form 7 additional settings box
 * `on_sent_ok: "alert('Unique2 ' + jQuery('#Unique2').val());"`
 * When unique2 is selected and send is click I would like it to redirect to another
   page.
 * I need a code doctor
 *  [Arun Singh](https://wordpress.org/support/users/arun_sparx/)
 * (@arun_sparx)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663604)
 * hello naturalworth,
 * I visited your site. I think you are still unable to fix the problem. Your change
   in the code is wrong:
    you should put only :
 *     ```
       if (1 == data.mailSent) {
       		if (data.onSentOk)
       			jQuery.each(data.onSentOk, function(i, n) { eval(n) });
   
       		jQuery(data.into).find('form').resetForm().clearForm();
       		wpcf7ResponseOutput.addClass('wpcf7-mail-sent-ok');
       	} else {
       ```
   
 * in spite of presently :
 *  `if (1 == data.mailSent) {
    jQuery(data.into).find(‘form’).resetForm().clearForm();
   wpcf7ResponseOutput.addClass(‘wpcf7-mail-sent-ok’);
 *  if (data.onSentOk)
    jQuery.each(data.onSentOk, function(i, n) { eval(n) }); }
   else {if (1 == data.mailSent) { if (data.onSentOk) jQuery.each(data.onSentOk,
   function(i, n) { eval(n) });
 *  jQuery(data.into).find(‘form’).resetForm().clearForm();
    wpcf7ResponseOutput.
   addClass(‘wpcf7-mail-sent-ok’); } else {`
 * replace the whole code with this.
 * Post back you still find some problem.
    Thanks

Viewing 14 replies - 1 through 14 (of 14 total)

The topic ‘[Plugin: Contact Form 7] Conditional Redirect?’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

 * 14 replies
 * 8 participants
 * Last reply from: [Arun Singh](https://wordpress.org/support/users/arun_sparx/)
 * Last activity: [14 years, 10 months ago](https://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect/#post-1663604)
 * Status: resolved