Wednesday, March 1, 2017

How to add Password Custom field in Contact form 7.

First of all add this below code to your theme’s functions.php file.
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');
Now we create a form with contact form 7 plugin with the following three fields: usernameemail and password
<p>Your Username (required)<br />
   [text* username] </p>

<p>Your Email (required)<br />
  [email* email] </p>

<p>Your Password<br />
  [text* password] </p>

<p>[submit "Register"]</p>
Now if we hide password field like (***) of the contact form then write following short code into your post:
[cfp id="7" title="Test" pwd="password"]

9 comments:

  1. get this error [contact-form-7 404 "Not Found"]

    ReplyDelete
  2. 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');

    ReplyDelete
  3. does this include confirm email field?

    ReplyDelete
  4. Hi,
    how will you specify the number of characters. Ex: Password must be between 8-20 characters

    ReplyDelete
  5. wordpress contact email
    Call Wordpress Phone Number 888-581-0004, Email, Chat Contact information. WordPress Support, Help, Errors, Migration,Hosting, WooCommerce. Call Now.

    ReplyDelete
  6. tried this but no luck.please help

    ReplyDelete
  7. How to Make Money with Money: Tips and Tricks for Your Online
    Money: Making money 샌즈카지노 on online gambling 메리트카지노 is one of the most important tasks people all come to The reason for หาเงินออนไลน์ doing it is simple:

    ReplyDelete
  8. my password field showing the content. how to make it proper password field in contact form 7??

    ReplyDelete