WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[trick] Password fields in Contact Form 7 (1 post)

  1. marchenko.alexandr
    Member
    Posted 1 year ago #

    So if you, for some reasons want to get password fields (that not supported for that moment by cf7) you can do it by adding somewhere in your functions.php following code:

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

    How it works:

    Lets assume that you have following form:

    [contact-form-7 id="7" title="Test"]

    With following content:

    <p>Your Name (required)<br />
        [text* your-name] </p>
    
    <p>Your Email (required)<br />
        [email* your-email] </p>
    
    <p>Subject<br />
        [text your-subject] </p>
    
    <p>Your Message<br />
        [textarea your-message] </p>
    
    <p>[submit "Send"]</p>

    And want to hide email field (notice how you named it in form body your-email)

    Write following short code into your post:

    [cfp id="7" title="Test" pwd="your-email"]

    This short code will print your cf7 form but before that will change input types to password.

    http://wordpress.org/extend/plugins/contact-form-7/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by marchenko.alexandr
  • This topic is not a support question
  • WordPress version: 3.4.2