php - How to use Elementor Form to create a password confirmation?
Get the solution ↓↓↓I am a beginner of coding and building a website so please forgive my dumb question below. I am trying to use Elementor's form widget to build a registration form. I found some code that worked well, but it failed when I tried to add password confirmed function.
This is the code I found.
add_action( 'elementor_pro/forms/new_record', 'thewpchannel_elementor_form_create_new_user' , 10, 2 );
function thewpchannel_elementor_form_create_new_user($record,$ajax_handler)
{
$form_name = $record->get_form_settings('form_name');
//Check that the form is the "create new user form" if not - stop and return;
if ('Create New User' !== $form_name) {
return;
}
$form_data = $record->get_formatted_data();
$username=$form_data['Username']; //Get the value of the input with the label "User Name"
$password = $form_data['Password']; //Get the value of the input with the label "Password"
$email=$form_data['Email']; //Get the value of the input with the label "Email"
$user = wp_create_user($username,$password,$email); // Create a new user, on success return the user_id no failure return an error object
if (is_wp_error($user)){ // if there was an error creating a new user
$ajax_handler->add_error_message("Failed to create new user: ".$user->get_error_message()); //add the message
$ajax_handler->is_success = false;
return;
}
$first_name=$form_data["First Name"]; //Get the value of the input with the label "First Name"
$last_name=$form_data["Last Name"]; //Get the value of the input with the label "Last Name"
wp_update_user(array("ID"=>$user,"first_name"=>$first_name,"last_name"=>$last_name)); // Update the user with the first name and last name
I tried to add this between line 11 and line 12. However it doesn't work.
$password_confirmation = $form_data['Confirmed Password']; //Get the value of the input with the label "Confirmed Password"
$email=$form_data['Email']; //Get the value of the input with the label "Email"
if ($password_confirmation != $password){
В В В В $ajax_handler->add_error_message("Password does not match"); //add the message
return;
Thanks for reading my question.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: failed to create image decoder with message 'unimplemented'
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.