[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?
-
Yes. Try
on_sent_ok: “alert(‘Technician ‘ + jQuery(‘#technicians’).val());”
Nope. The value just keeps coming back as ‘null’.
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?
No one can verify it if you don’t tell the URL of the page.
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.
That did the trick!! Thanks so much!
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”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…
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
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
The topic ‘[Plugin: Contact Form 7] Conditional Redirect?’ is closed to new replies.