WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] Conditional Redirect? (15 posts)

  1. Casey Picker
    Member
    Posted 3 years ago #

    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?

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    Yes. Try

    on_sent_ok: "alert('Technician ' + jQuery('#technicians').val());"

  3. Casey Picker
    Member
    Posted 3 years ago #

    Nope. The value just keeps coming back as 'null'.

  4. Casey Picker
    Member
    Posted 3 years ago #

    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?

  5. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    No one can verify it if you don't tell the URL of the page.

  6. Casey Picker
    Member
    Posted 3 years ago #

  7. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  8. Casey Picker
    Member
    Posted 3 years ago #

    That did the trick!! Thanks so much!

  9. cporichie
    Member
    Posted 3 years ago #

    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"

  10. amitkatoch
    Member
    Posted 3 years ago #

    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());"

  11. manku.patel
    Member
    Posted 3 years ago #

    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:)

  12. manku.patel
    Member
    Posted 3 years ago #

    i am done with all the above ideas......plz guys help me...

  13. suso
    Member
    Posted 3 years ago #

    This is just what i need!! but not a pop-up!! i need to redirect to page A if A, else page B...

  14. naturalworth
    Member
    Posted 3 years ago #

    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

    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

  15. Arun Singh
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic