duanji5116 2016-02-09 09:48
浏览 38
已采纳

将URL值存储在联系表单7的cookie中

I'd like to grab a value from my URL to pass it through to a hidden fields in Wordpress Contact Form 7.

For example, www.domain.com/?refid=1

Does anyone have any ideas on the best way this could be achieved?

I've got something alone the lines of the following to set the cookie:

< ?php if (isset($_GET['refid'])) { setcookie('COOKIE_refid',    $_GET['refid'], (86400*30)); } ?>

Would this cookie store what I'm after?

Many thanks.

  • 写回答

1条回答 默认 最新

  • drpzr64329 2016-02-09 16:52
    关注

    Would this cookie store what I'm after?

    Have you tried it? It looks like it would create a 30 day cookie like such:

    COOKIE_refId=1
    

    If you want a hidden field, though, then this is not the solution. While the user will not see the cookie (unless they have some sort of packet sniffer or cookie inspector installed), this is not actually a hidden field. To send through a hidden field, you could try something like this when you write out the page with the contact form:

    <!DOCUMENT HTML>
    <html>
        <head>
            <title>Hidden Field Example</title>
        </head>
        <body>
            <form method="POST" action="contact.php" id="contactform">
                <!-- ... Your contact form fields here... -->
    <?php
        // Check if we need to output a refid hidden form field
        if(isset($_GET['refid']) && !empty($_GET['refid'])){
            // Use echo to send the hidden refid form field to the output stream/buffer
            echo "<input type='hidden' id='hiddenRefId' name='refid' value='$_GET['refid']'>";
        } /* else, there is no refid to include as a hidden field */
    ?>
            </form>
        </body>
    </html>
    

    I do not know the exact semantics of Contact Form 7 for Wordpress, but that should give you a general idea.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi