I am building a website for one of my clients and they want a function into their website some thing like the following:
when people click the download link, a form will appear ( contact form 7) and after visitors put their details , it will re-directed to the download link.
I able to re-direct to a new page after form submission by using following additional setting to the contact form 7.
on_sent_ok: "location = 'http://example.com/';"
However, They have 10 files , I need to change the re-direction link 10 times to trigger the download for the appropriate file. I can do it by using 10 contact forms which will be very dirty.
Is there any way i can change the re-direction URL dynamically?
For example,
http://example.com/?id=1
http://example.com/?id=2
<?php
$id = $_GET['id'];
$url= "http://example.com/id=?". $id;
?>
is there any way to change the following Location with $url ?
on_sent_ok: "location = 'http://example.com/';"
I have found a way to change the redirection URL dynamically. I have followed the following steps to achieve the dynamic redirection:
In contact form 7’s Additional setting put the following:
on_sent_ok: ‘redirect();’
We need a hidden field to carry a piece of necessary information. However, Contact form 7 by default do not allow us to create hidden fields. The developer SevenSpark has developed an extension to allow hidden fields in Contact form 7.
http://wordpress.org/extend/plugins/contact-form-7-dynamic-text-extension/
please download the plugin and install. you will see two new tags have been generated for the contact form 7. this will allow you to grab the value from $_GET variable. please check the details on plugin page.
ex. http://example.com/?foo=“bar”
Create a template page or exiting page template ok.
assign the template to the appropriate page. if you want to use the default template you do not need to create or assign any template.
open your template file in an Editor.
paste the following code:
Now browse the link with GET parameter.
ex. http://example.com/?redFilename=“apple”
the hidden field of the contact form 7 will capture the redFilename value. if form submission is successful, it will redirect to the http://example.com/thankyou_orange/ page
Enjoy!!!!
Contact form 7 Redirecting to Another URL After Submissions 2017 Updates
First you need to update contact form 7 on new version i try it on v7.4.9 and then place a contact form short code in any page and place this JS script any where on page and change url where need to redirect your page after submission
For more info click contact form 7 official site https://contactform7.com/redirecting-to-another-url-after-submissions/
on_sent_ok:
never worked for me.I tried something like this for tracking conversation.
I went down the Javascript route, which works… but you then don’t have access to the submitted variables (at least I couldn’t see how you would). Here I have ported my Javascript code across to PHP code.
You can access any hidden or displayed inputs in the form and use them to build the URL.
There is one required trick to do the redirect in PHP rather than Javascript, which is that you have to turn off the CF7 Javascript as per the doc. Put this in your
wp-config.php
:Then you can put this in your theme
functions.php
: