Video tutorial about how to use PHP and Elementor Pro forms, in order to create a registration form.
Create Registration Form Using Elementor Pro
<?php
/**
 * Plugin Name: Elementor Form Create New User
 * Description: Create a new user using elementor form
 * Author:      Gal Hadad
 * Author URI:  https://wpsite.co.il
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

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['User Name']; //Get tne value of the input with the label "User Name"
    $password = $form_data['Password']; //Get tne value of the input with the label "Password"
    $email=$form_data['Email'];  //Get tne 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 tne value of the input with the label "First Name"
    $last_name=$form_data["Last Name"]; //Get tne 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


    /* Automatically log in the user and redirect the user to the home page */
    $creds= array( // credientials for newley created user
        "user_login"=>$username,
        "user_password"=>$password,
        "remember"=>true
    );
    $signon = wp_signon($creds); //sign in the new user
    if ($signon)
        $ajax_handler->add_response_data( 'redirect_url', get_home_url() ); // optinal - if sign on succsfully - redierct the user to the home page
}
Share on facebook
Facebook
Share on google
Google+
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on print
Print

7 thoughts on “Create Registration Form Using Elementor Pro”

  1. Hi Gal,
    Nice tutorial! Many thanks for sharing your knowledge.
    I found your article by searching for a solution related to this webhook and a wp_query.
    I am creating a giveaway in my WordPress installation. When a user entry is created I save it to a CPT (my code is similar to yours, uglier, but similar), that works great.
    But, I have another post type that is the giveaway, where I set the prize, the winners quantity, etc. I have another Elementor form there which picks the winner with a wp_query over the user entries CTP. I use the same webhook for both forms, filtering by the form name to know when to create an entry or when to pick winner. The thing is that when trying to get post by wp_query to pick a winner I get a nasty 500 server error “Failed to load resource: the server responded with a status of 500 (/wp-admin/admin-ajax.php:1 )”.
    So, I have 2 questions:
    1. The easy one, how can I make this work? I would be nice to teak a few things and don’t trough my work away.
    2. The hard one, Is this the correct way to achieve this? Should I start over with a different approach?

    Many thanks!.
    Best

    1. Hi Gustavo, Server Error 500, is just the server way to say “there was an error”, You should check the error logs in the server to find out more about it.
      Or you can put your site in debug mode by pasting this code in wp-config.php (only do this if your site isn’t live):
      define('WP_DEBUG', true);
      define('WP_DEBUG_LOG', true);
      define('WP_DEBUG_DISPLAY', true);
      @ini_set('display_errors', E_ALL);

      Overall your method should work.

  2. Hi Gal! Nice work
    Is there a way to create a used database separate from the main user database? I want the people who sign up as users to be different from the page admins and once they sign up to be taken to a separate dashboard where they can see some info specifically to them. Is there a way to do that or should I think about designing a whole interface from scratch with PHP?

  3. Hey Gal, i watched your video and it is very nice, thank you for the help but i have a problem, i created a popup form with elementor pro and do all steps like you in the video but it nothing happens. I activated the plugin and checked the form name but it will not create any new user… Can u help me pls? 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *