Contact Form 7 Add Password field

The plugin is to add a password filed to Contact form 7 plugin.
ex. [password example] (optional) / [password* example] (required)

Contact Form 7 Add Password field


  • 21 November, 2021: Version 2.92

In this section, we will introduce the validation check using hooks implemented in 2.9.

How to use the hook

The following is an example of how to write the supported hooks in the functions.php function for the theme. Using hooks, you can change or add validation checks for this plugin from fucntions.php or plugins. Always consider the necessity of escaping when retrieving form data such as $_POST and $_GET.

Example 1. Check if the password is the same as the WordPress login user’s password (21 July, 2021)

Checks if the data entered in the password field of Contact Form 7 and the password of the WordPress login user match.

[password* password2]

Suppose you have set up the system as shown above.
Let’s compare it with the sample user’s password.

WordPress stores passwords in Hash format, but there are two types of passwords: one is unique to WordPress, and the other is hashed with MD5. Use the “wp_check_password” function to check for these.

What you need to understand.
1. Get the password data from the form you entered ($_POST[‘password2’]).
2. Get the hashed password and ID of the WordPress sample user.

  1. Check your password

Example of “functions.php” in the theme.

In the following example, the data obtained by $_POST is only compared, and the password is not escaped because it contains symbols.

Below is TiPS using Contact Form 7.

Registering as a user on WordPress (22 July, 2021)

The following example shows how to make a user enter his/her username, password, and email address using Contact Form 7 and this plugin, and then register the user with WordPress using Contact Form 7’s wpcf7_mail_sent hook after pressing submit. Existing users, error messages when registering, and various other settings need to be replaced.

So don’t just copy and paste the following and use it, be sure to review the settings.
If you set a password too easily, you can create a WordPress user without permission. Please think about how to prevent people from setting easy passwords (e.g. [password* password2 password_min:12 password_strength:4]). Please keep in mind that the following is just the simplest code example.

The following is the code that we expect to add to the functions.php of the theme.

  • Username: Obtained from [text* your-name] in Conctact Form 7.
  • Password: Obtained from [password* password2] by using this plugin.
  • Email address: Obtained from [text* your-email] in Conctact Form 7.
  • User role: contributor (See Summary of Roles at Set all lowercase when setting.

Assume that you have entered data with the above settings.

Created 21 July, 2021