WordPress表单插件 Contact form 7介绍及拓展高级功能实现和部分表单框架样式

2023-05-16 13:13:23 浏览数 (1)

什么是Contact form 7 ?

代码语言:txt复制
    zuanmang.net
代码语言:txt复制
    zuanmang.net

首先  Contact form 7 插件是一款免费的WordPress表单插件,用于给访客填写表单、收集信息功能。利用配合MailChimp(国外邮件营销工具)亦可实现邮件订阅功能, 由于Contact Form7插件的强大,也可以实现自动给用户发送邮件(可包含文件附件),配合Contact Form CFDB7插件可记录用户表单填写信息(Contact form 7插件默认是不会保存这些内容的,它只会发送邮件发给你 );配合Redirection for Contact Form 7 插件也实现用户提交表单后跳转至自定义url。可用于记录跳转参数便于运营数据参考,这款插件还可以将用户填写的信息传递到url,以实现简单的跨页面传参呈现用户信息。

总结一下配合使用的插件

由于Contact form 7 轻量迷你且免费,所以很多功能的实现需要配合其他辅助插件使用

如下:(不提供插件下载,这些基本后台都可以搜索得到)

  • Contact form 7 插件:Contact form 7
  • 配合同步到MailChimp:Contact Form 7 Extension For Mailchimp
  • 配合记录用户填写的表单:Contact Form CFDB7
  • 配合提交后跳转url和链接传参:Redirection for Contact Form 7
  • 配合弹窗插件:JetPopup (内附多套样式,便于参考或修改)
  • 推荐好用的页面构建器: Elementor
创建完表单如何实现插入到页面呢?

非常简单,Contact form 7新建表单后会生成一串短代码,将短代码插入到文章相应位置即可。如下图:

当然,配合上边推荐的Elementor元素插件(页面构建器),可以通过Elementor内在模块快捷插入Contact form 7表单。

如果你想实现弹窗让访客提交表单信息,实际上你只需要借助别的插件弹窗,弹窗内容插入Contact form 7表单的短代码即可实现。反正就是一句话,想以什么方式呈现,就把短代码放到相应位置即可。弹窗功能可以使用Elementor插件实现。

Contact form 7进阶操作

Contact form 7插件提供了非常多的内置函数字段以帮助我们拓展功能,我们可以利用这些来收集访客 ip 浏览器ua  提交页面等。

列举几个常用的字段:
  • 用户表单信息(默认情况字段):your-email
  • 提交用户ip:_remote_ip
  • 提交时间:_time
  • 提交用户浏览器信息:_user_agent
如何在表单内收集用户上传文件并通过email邮件附件发送给我们?

可以利用表单内的插入文件标签,实现前端用户文件上传。

要实现自动发送给我的email,只需要将file 自定义字段名表单填写到mall项(就是用户提交表单后发送email配置) 的File attachments内即可。如下图:

上边这一串是 前边所定义的字段,这里插件帮你总结出来,方便你插入标签。

另外提一下,如果你想利用Contact form 7插件在用户填写完表单后给他发送邮件,可以点击下边的 Mail(2) 这里的意思就是多开一项发送的邮件。但他是可独立设置的。如图:

本地附件字段格式:

代码语言:javascript复制
[your-file][your-another-file]
uploads/2020/07/zmki.pdf

插件的函数标签 官方还有很多,这里暂且只写出了这么多,有兴趣可以去官网文档了解一下: Special mail-tags

下边提供一些比较常见的表单结构(共110套),使用方法如下

  • 10套表单在线演示 demo: www.hunktest.com/contact-form-7
  • 本文提供的表单代码为了方便快速创建表单结构,如需要外观比较完美展现  还需要自己一定动手能力。
  • 在安装好的contact form7的WordPress中新建表单,然后把下面的表单代码复制进去。
  • 下列的表单为了美观基本上都有自己的css,需要你引入到使用的页面。比如放到主题的style.css内
  • 部分表单 字段比默认的多,所以在你做好表单之后。将表单内多出的字段复制到 邮件发送项,避免用户填写完之后无法接收到。
  • 另外,部分按钮由于css没有给他定义颜色,会根据你的主题默认颜色呈现。
表单常见元素css修改 类名称参考 示例:

输入框高度

代码语言:javascript复制
.wpcf7-form-control-wrap input{height:30px!important;}

输入框外部下边距

代码语言:javascript复制
.wpcf7-form-control-wrap textarea{height:100px!important;}

信息框高度

代码语言:javascript复制
.wpcf7 p{margin-bottom:10px!important;}
可以快捷在插件类写入css,不过有时候不会生效,插件原因不生效可以丢到主题内的样式表里边。

示例表单开始:

表单编号CF71

表单代码:

代码语言:javascript复制
<div class="hunkcf71"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-envelope-o"></i> We will answer your email shortly!</p><p>[text* your-name placeholder "Your name*"]</p>

<p>[email* your-email placeholder "Email Address*"]</p>

<p>[text your-subject placeholder "Your website*"]</p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p>[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.nodisplay{display:none!important;}

表单2号:

表单代码:

代码语言:javascript复制
<div class="hunkcf72"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-envelope-o"></i> We will answer your email shortly!</p><p><div class="outer"><div class="cf7part onethird"><div class="inner">[text* your-name placeholder "Your name*"]</div></div></div>

<div class="outer"><div class="cf7part onethird"><div class="inner">[email* your-email placeholder "Email Address*"]</div></div></div>

<div class="outer"><div class="cf7part onethird"><div class="inner">[text your-subject placeholder "Your website*"]</div></div></div></p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p>[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.onethird{width:33.33333333333%;float:left!important;}

.outer{margin:0 -10px;}

.inner{padding:0 10px;}.outer{margin:0 -10px;}

.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.onethird{width:100%!important;}}

表单3号:

表单代码:

代码语言:javascript复制
<div class="hunkcf73"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-envelope-o"></i> We will answer your email shortly!</p><p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text* your-name placeholder "Your name*"]</div></div></div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[email* your-email placeholder "Email Address*"]</div></div></div></p>

<p>[text your-subject placeholder "Your website*"]</p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p>[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.onethird{width:33.33333333333%;float:left!important;}

.onehalf{width:50%;float:left!important;}

.outer{margin:0 -10px;}

.inner{padding:0 10px;}.outer{margin:0 -10px;}

.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.onethird,.onehalf{width:100%!important;}}

表单4号:

表单代码:

代码语言:javascript复制
<div class="hunkcf74"><p class="cf7-title" style="font-size:27px;"><i class="fa fa-envelope-o"></i> We will answer your email shortly!</p><p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text* your-name placeholder "Your name*"]</div></div></div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[email* your-email placeholder "Email Address*"]</div></div></div></p>

<p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text your-phone placeholder "Your Phone*"]</div></div> </div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[text your-subject placeholder "Your website*"]</div></div></div></p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p class="submit">[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.onehalf{width:50%;float:left!important;}

.outer{margin:0 -10px;}

.inner{padding:0 10px;}.outer{margin:0 -10px;}

.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.onehalf{width:100%!important;}}

.hunkcf74 .wpcf7-text{border:2px solid #e0e0e0!important;height:50px!important;font-size:16px!important;border-radius:5px;}

.hunkcf74 textarea{border:2px solid #e0e0e0!important;font-size:16px!important;border-radius:5px;}

.hunkcf74 .submit{text-align:center;font-size:16px!important;}

.hunkcf74 .submit .wpcf7-submit{padding:15px 60px!important;background:#fff!important;color:#3B5998!important;border:2px solid #3B5998!important;border-radius:5px;font-weight:700!important;}

.hunkcf74 .submit .wpcf7-submit:hover{background:#3B5998!important;color:#fff!important;}

由于本表单比默认表单多了一个表格,所以需要还需要在Contact form 7设置菜单- Mail里面的message body里面任何位置加上your-phone,然后更新即可。如果不加这一段代码,那收到 询盘中就没有客户填的电话信息

表单5号:

表单代码:

代码语言:javascript复制
<div class="hunkcf75"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-envelope-o"></i> We will answer your email shortly!</p><p><span class="spanleft">Your Name *</span>[text* your-name]</p>

<p><span class="spanleft">Your Email *</span>[email* your-email]</p>

<p><span class="spanleft">Your Website *</span>[text your-subject]</p>

<p><span class="spanleft">Your Discription *</span>[textarea* your-message]</p>

<p class="submit">[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.hunkcf75 .wpcf7-form-control-wrap{display:inline-block;width:250px!important;}

.hunkcf75 .wpcf7-form-control{text-align:right!important;}

.spanleft{width:120px!important;display:inline-block;}

.hunkcf75 .submit{text-align:center;}


.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.spanleft,.hunkcf75 .wpcf7-form-control-wrap{display:block!important;}}

表单6号:

表单代码:

代码语言:javascript复制
<div class="hunkcf76"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-smile-o"></i> We will answer your email shortly!</p><p><span class="span6">Your Name *</span>[text* your-name]</p>

<p><span class="span6">Your Email *</span>[email* your-email]</p>

<p><span class="span6">Your Website *</span>[text your-subject]</p>

<p><span class="span6">Your Discription *</span>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p class="submit">[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.hunkcf76 .wpcf7-text{border}

.nodisplay{display:none!important;}


.hunkcf76 input,.hunkcf76 textarea{border-width:0 0 1px!important;padding-left:0!important;}

.hunkcf76 .submit{text-align:center!important;}

.hunkcf76 .wpcf7-submit{padding:13px 40px!important;background:#303030!important;border:1px solid #303030!important;}

.hunkcf76 .wpcf7-submit:hover{background:#fff!important;color:#303030!important;}

表单7号:

表单代码:

代码语言:javascript复制
<div class="hunkcf77"><p class="cf7-title" style="font-size:27px;text-align:center;"><i class="fa fa-envelope-o"></i> Contact us today</p><p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text* your-name placeholder "Your name*"]</div></div></div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[email* your-email placeholder "Email Address*"]</div></div></div></p>

<p>[text* your-company placeholder "Your company name*"]</p><p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text your-subject placeholder "Your website*"]</div></div> </div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[text your-phone placeholder "Your phone *"]</div></div></div></p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p class="submit">[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.onehalf{width:50%;float:left!important;}

.outer{margin:0 -10px;}

.inner{padding:0 10px;}.outer{margin:0 -10px;}

.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.onehalf{width:100%!important;}}

.hunkcf77 input{height:55px!important;background:#eee!important;border:none!important;border-radius:30px!important;font-size:17px!important;padding:15px 30px 15px 30px!important}


.hunkcf77 textarea{height:200px!important;background:#eee!important;border:none!important;border-radius:30px!important;font-size:17px!important;padding:15px 30px 15px 30px!important}

.hunkcf77 .submit{text-align:center!important;}

.hunkcf77 .submit .wpcf7-submit{padding:15px 40px!important;background:#fff!important;border-radius:30px!important;border:1px solid #333!important;color:#333!important;}

.hunkcf77 .wpcf7-submit:hover{background:#333!important;color:#fff!important;}

由于本表单比默认表单多了一个表格,所以需要还需要在Contact form 7设置菜单- Mail里面的message body里面任何位置加上your-phone,然后更新即可。如果不加这一段代码,那收到询盘中就没有客户填的电话信息

表单8号:

表单代码:

代码语言:javascript复制
<div class="hunkcf78"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-envelope-o"></i> Get in touch</p><p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text* your-name placeholder "Your name*"]</div></div></div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[email* your-email placeholder "Email Address*"]</div></div></div></p>

<p>[text your-subject placeholder "Your phone*"]</p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p>[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.onehalf{width:50%;float:left!important;}

.outer{margin:0 -10px;}

.inner{padding:0 10px;}.outer{margin:0 -10px;}

.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.onehalf{width:100%!important;}}

.hunkcf78 input{height:55px!important;font-size:17px!important;padding:15px 40px!important;}

.hunkcf78 textarea{height:200px!important;font-size:17px!important;padding:15px 40px!important;}

.hunkcf78 .your-name input{background:url(https://www.hunktest.com/wp-content/uploads/2018/06/user.png);background-repeat:no-repeat;background-position:10px center;}

.hunkcf78 .your-email input{background:url(https://www.hunktest.com/wp-content/uploads/2018/06/email.png);background-repeat:no-repeat;background-position:10px center;}

.hunkcf78 .your-subject input{background:url(https://www.hunktest.com/wp-content/uploads/2018/06/phone.png);background-repeat:no-repeat;background-position:10px center;}

.hunkcf78 .your-message textarea{background:url(https://www.hunktest.com/wp-content/uploads/2018/06/comment.png);background-repeat:no-repeat;background-position:10px 13px;}

表单9号:

表单代码:

代码语言:javascript复制
<div class="hunkcf79"><p class="cf7-title" style="font-size:25px;color:#fff;"><i class="fa fa-envelope-o"></i> GETTING IN TOUCH!</p>

<p>[text* your-name placeholder "Your name*"]</p>

<p>[email* your-email placeholder "Email Address*"]</p>

<p>[text your-subject placeholder "Your phone*"]</p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p class="submit">[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.hunkcf79{background:#ff9800;padding:20px;}

.hunkcf79 input, .hunkcf79 textarea{border:none!important;border-radius:3px!important;}

.nodisplay{display:none!important;}

.hunkcf79 .your-name input{padding:13px 40px!important;background:url(https://www.hunktest.com/wp-content/uploads/2018/06/person.png);background-repeat:no-repeat;background-position:10px center;background-color:#fff;}

.hunkcf79 .your-email input{padding:13px 40px!important;background:url(https://www.hunktest.com/wp-content/uploads/2018/06/email-one.png);background-repeat:no-repeat;background-position:10px center;background-color:#fff;}

.hunkcf79 .your-subject input{padding:13px 40px!important;background:url(https://www.hunktest.com/wp-content/uploads/2018/06/call.png);background-repeat:no-repeat;background-position:10px center;background-color:#fff;}

.hunkcf79 .your-message textarea{padding:13px 40px!important;background:url(https://www.hunktest.com/wp-content/uploads/2018/06/pen.png);background-repeat:no-repeat;background-position:10px 10px;background-color:#fff;}


.hunkcf79 .wpcf7-submit{width:100px!important;height:100px!important;background:red!important;border:3px solid #fff!important;border-radius:50px!important;font-size:16px!important;font-weight:700!important;}

.hunkcf79 .wpcf7-submit:hover{transform:rotate(45deg);}

.hunkcf79 .submit{text-align:center!important;margin-top:-70px!important;}

表单10号:

表单代码:

代码语言:javascript复制
<div class="hunkcf710"><p class="cf7-title" style="font-size:25px;"><i class="fa fa-envelope-o"></i> Contact us</p><p><div class="outer"><div class="cf7part onehalf"><div class="inner">[text* your-name placeholder "Your name*"]</div></div></div>

<div class="outer"><div class="cf7part onehalf"><div class="inner">[email* your-email placeholder "Email Address*"]</div></div></div></p>

<p>[text your-subject placeholder "Your website*"]</p>

<p>[textarea* your-message placeholder "Give us your need as specific as possible*"]</p>

<p>[submit "Send"]</p>

<div class="nodisplay">made by <a href="https://www.imhunk.com/">imhunk</a></div>

</div>

CSS代码:

代码语言:javascript复制
.onehalf{width:50%;float:left!important;}

.outer{margin:0 -10px;}

.inner{padding:0 10px;}.outer{margin:0 -10px;}

.cf7part{float:left;margin-bottom:20px;}

.nodisplay{display:none!important;}

@media only screen and (max-width: 640px)

{.onehalf{width:100%!important;}}

.hunkcf710{border:none; box-shadow: darkgrey 10px 10px 30px 5px;padding:20px;}

.hunkcf710 .your-name input, .hunkcf710 .your-email input, .hunkcf710 .your-subject input{height:35px!important;}

.hunkcf710 input,.hunkcf710 textarea{border:none!important;background:#eee!important;font-size:15px!important;}

.hunkcf710 .wpcf7-submit{border:1px solid #333!important;background:#333!important;}

.hunkcf710 .wpcf7-submit:hover{background:#fff!important;color:#333!important;}

相关链接:

  • Contact Form 7官网: contactform7.com
  • Contact Form 7 标签官方文档: contactform7.com/special-mail-tags
  • Contact Form 7  邮件设置文档:contactform7.com/setting-up-mail
  • 10套主题代码&功能标签参考来自: www.imhunk.com/contact-form-7

0 人点赞