如何自动填写联系表7

问题描述 投票:0回答:4

在我的网站上,我使用联系表 7 将价目表发送给我们的潜在客户。他们只需要填写姓名和电子邮件即可。如果客户想要预订我们的服务,只需单击电子邮件中的链接即可进入另一个预订表格。 我认为要求他们再次填写姓名和电子邮件看起来不太好,所以我想知道是否有办法从 cookie 或类似的东西自动填充? 提前非常感谢

wordpress cookies contact-form-7 autofill
4个回答
6
投票

现在您可以简单地从“context”获取它们,因此不需要插件。 您可以使用

$_GET
$_POST
post_meta
字段,如下所示:

如果您加载 example.com?your-name=John,它将从

$_GET

填充该字段
[text* your-name default:get]

或者如果您的帖子有一个名为

your-name

的 post_meta 字段
[text* your-name default:post_meta "Your Name"]

0
投票

您可以使用这个 Dynamic Contact Form 7 插件 并将 $_GET supergobal 添加到 URL 中吗?即

example.com/contact/?first="John"&last="Cena"


0
投票

电话号码呢?我想使用自动填充电话号码。


-2
投票

我将尝试用一个例子来描述这个过程。

假设表单的结构是:

<label>First Name: [text first_name]</label>
<label>Last Name: [text last_name]</label>
<label>Email: [email email]</label>

并且您希望使用作为 URL 参数接收的值预先填充这些字段,例如:

http://www.your-website-domain.com/page-with-the-form/?first_name=John&last_name=Doe&email=john.doe@email.com

在表单内容末尾输入以下代码:

<script>
    var urlParams = new URLSearchParams(window.location.search);
    if(urlParams.has('first_name')) 
        document.getElementsByName('first_name')[0].value = urlParams.get('first_name');
    if(urlParams.has('last_name')) 
        document.getElementsByName('last_name')[0].value = urlParams.get('last_name');
    if(urlParams.has('email')) 
        document.getElementsByName('email')[0].value = urlParams.get('email');
</script>

因此,完整表单的结构(在这个假设的情况下)将是:

<label>First Name: [text first_name]</label>
<label>Last Name: [text last_name]</label>
<label>Email: [email email]</label>
<script>
    var urlParams = new URLSearchParams(window.location.search);
    if(urlParams.has('first_name')) 
        document.getElementsByName('first_name')[0].value = urlParams.get('first_name');
    if(urlParams.has('last_name')) 
        document.getElementsByName('last_name')[0].value = urlParams.get('last_name');
    if(urlParams.has('email')) 
        document.getElementsByName('email')[0].value = urlParams.get('email');
</script>

仅此而已。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.