WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Contact Form 7] Conditional Redirect?

[Resolved] [Plugin: Contact Form 7] Conditional Redirect?

  • Casey Picker
    Member

    @ckpicker

    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
    Participant

    @takayukister

    Yes. Try

    on_sent_ok: “alert(‘Technician ‘ + jQuery(‘#technicians’).val());”

    Casey Picker
    Member

    @ckpicker

    Nope. The value just keeps coming back as ‘null’.

    Casey Picker
    Member

    @ckpicker

    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
    Participant

    @takayukister

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

    Casey Picker
    Member

    @ckpicker

    Plugin Author Takayuki Miyoshi
    Participant

    @takayukister

    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.

    Casey Picker
    Member

    @ckpicker

    That did the trick!! Thanks so much!

    cporichie
    Member

    @cporichie

    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
    Member

    @amitkatoch

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

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

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

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

    naturalworth
    Member

    @naturalworth

    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

    Arun Singh
    Member

    @arun_sparx

    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 ‘[Resolved] [Plugin: Contact Form 7] Conditional Redirect?’ is closed to new replies.