【问题标题】:How to set a password field in WPCF7 (Contact Form 7)如何在 WPCF7 中设置密码字段(联系表 7)
【发布时间】:2021-06-02 21:01:55
【问题描述】:

我在 wordpress 网站中使用联系表 7 来构建登录表单。在我的表单中,我想添加一个密码字段,但此插件中似乎缺少此字段。

你能帮帮我吗?谢谢

【问题讨论】:

    标签: php wordpress contact-form-7


    【解决方案1】:

    如果有人遇到与上述相同的问题,(尽管不推荐)存在解决方案。您可以通过 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');
    

    【讨论】:

      【解决方案2】:

      这超出了 CF7 的范围,它仅用于发送电子邮件,并且由于电子邮件的开放性,不建议发送带有密码或内容的任何内容。

      【讨论】:

        【解决方案3】:

        这就是你使这段代码工作的方式:

        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');
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-12-19
          • 2022-01-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-10-15
          • 2014-07-26
          相关资源
          最近更新 更多