如何更改联系表 7 动态重定向 URL - WordPress [英] How to change contact form 7 Redirecting URL dynamically - WordPress

查看:21
本文介绍了如何更改联系表 7 动态重定向 URL - WordPress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的一位客户建立一个网站,他们希望在他们的网站中加入类似以下内容的功能:

当人们点击下载链接时,会出现一个表格(联系表格 7),访问者输入他们的详细信息后,它会重定向到下载链接.

通过使用以下联系表单 7 的附加设置,我可以在提交表单后重定向到新页面.

on_sent_ok: "location = 'http://example.com/';"

但是,他们有 10 个文件,我需要更改重定向链接 10 次才能触发相应文件的下载.我可以通过使用 10 个联系表格来完成,这会很脏.

有什么办法可以动态更改重定向 URL?

例如

http://example.com/?id=1http://example.com/?id=2<?php$id = $_GET['id'];$url=http://example.com/id=?".$id;?>

有没有办法用 $url 更改以下位置?

on_sent_ok: "location = 'http://example.com/';"

解决方案

我找到了一种动态更改重定向 URL 的方法.我按照以下步骤来实现动态重定向:

  1. 在联系表格 7 的附加设置中输入以下内容:

    on_sent_ok: 'redirect();'

  2. 我们需要一个隐藏字段来携带一条必要的信息.但是,默认情况下,联系表单 7 不允许我们创建隐藏字段.开发商 SevenSpark 开发了一个扩展,允许在联系表单 7 中隐藏字段.http://wordpress.org/extend/plugins/contact-form-7-dynamic-text-extension/请下载插件并安装.您将看到为联系表单 7 生成了两个新标签.这将允许您从 $_GET 变量中获取值.请检查插件页面上的详细信息.

    例如.http://example.com/?foo="bar"

  3. 创建模板页面或退出页面模板即可.

  4. 将模板分配到适当的页面.如果要使用默认模板,则无需创建或分配任何模板.

  5. 在编辑器中打开您的模板文件.

  6. 粘贴以下代码:

  7. 现在浏览带有 GET 参数的链接.

    例如.http://example.com/?redFilename="apple"

联系表单 7 的隐藏字段将捕获 redFilename 值.如果表单提交成功,它将重定向到http://example.com/thankyou_orange/ 页面>

享受!!!!

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:

  1. In contact form 7's Additional setting put the following:

    on_sent_ok: 'redirect();'

  2. 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"

  3. Create a template page or exiting page template ok.

  4. 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.

  5. open your template file in an Editor.

  6. paste the following code:

    <script>    
    
        function redirect() {
    
    
    
            // your hidden field ID
               var filename = document.getElementById('redFilename').value;
    
            var url ='';
    
            //alert(document.getElementById('redFilename').value);
            if (filename == 'apple')
            {
    
    
                url= 'http://example.com/thankyou/';
    
    
            }
            else if (filename == 'orange')
            {
             url= 'http://example.com/thankyou_orange/';
            }    
    
    
     window.location = url;
    
            }
            </script>
    

  7. 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!!!!

这篇关于如何更改联系表 7 动态重定向 URL - WordPress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆