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

Latest

  • 20 August, 2023: Version 4.1

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 maxlength: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 https://wordpress.org/support/article/roles-and-capabilities/. Set all lowercase when setting.

Assume that you have entered data with the above settings.

Changing Contact Form 7 input values (28 January, 2023)

The following example is a TiPS to use when you want to keep passwords and other values secret. It cannot be embedded in this plugin but must be added to the functions.php of the theme.

  • Get the name of the item you want to change in Contact Form 7

Assume that you have had the data entered in the above settings.
*In following case, there are two fields to be changed here, “user-pass” and “check-user-pass” respectively. The entered values are hashed. This can be used to store passwords as hash values instead of using them as raw data.
Let’s assume that Contact Form 7 actually uses this plugin to create a password input and an input form to check it.

So, add the following code to your theme’s functions.php

If you do not want the user to enter a value, the code would look something like this

Created 21 July, 2021
Modified 28 January, 2023