【发布时间】:2021-06-02 21:01:55
【问题描述】:
我在 wordpress 网站中使用联系表 7 来构建登录表单。在我的表单中,我想添加一个密码字段,但此插件中似乎缺少此字段。
你能帮帮我吗?谢谢
【问题讨论】:
标签: php wordpress contact-form-7
我在 wordpress 网站中使用联系表 7 来构建登录表单。在我的表单中,我想添加一个密码字段,但此插件中似乎缺少此字段。
你能帮帮我吗?谢谢
【问题讨论】:
标签: php wordpress contact-form-7
如果有人遇到与上述相同的问题,(尽管不推荐)存在解决方案。您可以通过 here 找到一个这样的解决方案。
简而言之,您需要将以下脚本添加到您主题的functions.php 文件中:
<!-- language: lang-php -->
function cfp($atts, $content = null) {
extract(shortcode_atts(array( "id" => "", "title" => "", "pwd" => "" ), $atts));
if(empty($id) || empty($title)) return "";
$cf7 = do_shortcode('[contact-form-7 404 "Not Found"]');
$pwd = explode(',', $pwd);
foreach($pwd as $p) {
$p = trim($p);
$cf7 = preg_replace('/<input type="text" name="' . $p . '"/usi', '<input type="password" name="' . $p . '"', $cf7);
}
return $cf7;
}
add_shortcode('cfp', 'cfp');
【讨论】:
这超出了 CF7 的范围,它仅用于发送电子邮件,并且由于电子邮件的开放性,不建议发送带有密码或内容的任何内容。
【讨论】:
这就是你使这段代码工作的方式:
function cfp($atts, $content = null) {
extract(shortcode_atts(array( "id" => "", "title" => "", "pwd" => "" ), $atts));
if(empty($id) || empty($title)) return "";
$cf7 = do_shortcode('[contact-form-7 id="'. $id .'" title="' . $title . '"]');
$pwd = explode(',', $pwd);
foreach($pwd as $p) {
$p = trim($p);
$cf7 = preg_replace('/<input type="text" name="' . $p . '"/usi', '<input type="password" name="' . $p . '"', $cf7);
}
return $cf7;
}
add_shortcode('cfp', 'cfp');
【讨论】: