【问题标题】:Store URL value in cookie for Contact Form 7将 URL 值存储在 Contact Form 7 的 cookie 中
【发布时间】:2016-02-10 00:52:44
【问题描述】:

我想从我的 URL 中获取一个值,以将其传递到 Wordpress Contact Form 7 中的隐藏字段。

例如,www.domain.com/?refid=1

有人对实现这一目标的最佳方式有任何想法吗?

我只有以下几行来设置cookie:

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

这个 cookie 会存储我想要的东西吗?

非常感谢。

【问题讨论】:

    标签: php forms cookies contact


    【解决方案1】:

    这个 cookie 会存储我想要的东西吗?

    你试过了吗?看起来它会像这样创建一个 30 天的 cookie:

    COOKIE_refId=1
    

    但是,如果您想要一个隐藏字段,那么这不是解决方案。虽然用户不会看到 cookie(除非他们安装了某种数据包嗅探器或 cookie 检查器),但这实际上并不是一个隐藏字段。要通过隐藏字段发送,您可以在使用联系表单写出页面时尝试这样的操作:

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

    我不知道用于 Wordpress 的 Contact Form 7 的确切语义,但这应该可以让您大致了解。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2019-03-23
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多