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.

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

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改