I'm looking to create a user registration form on a Drupal 8 site that has multiple clearly defined sections (possibly on separate pages).

I've explored doing this with the standard Drupal registration form building tools in account settings but it doesn't seem possible to create a form with such a layout using just account settings (correct me if I'm wrong).

The webform module allows me to create a form which is styled exactly how I want but I'm not sure how to create a user account with data entered into a webform. Is there another module I can use for this or can I do it from within the webform module?

  • I've already done this before in a project a while back, you should be able to do this using Handlers in webform settings itself. you have to create a custom handler for saving a new user and use the webform's field data to achieve that, if you couldn't figure it out yourself, I'll leave an answer
    – Sohail
    Commented Oct 15, 2018 at 18:38
  • 1
    @Sohail Would be great if you could post an answer. Looking at the Handlers settings page it's not obvious how I can create a user. It looks like I can just send an email or post form data to a URL. Does this require some custom code to achieve? A google search seems to suggest this. Commented Oct 22, 2018 at 8:47
  • I'll try to see if I can get a working handler for this till tomorrow
    – Sohail
    Commented Oct 23, 2018 at 15:06
  • I updated the answer, please take a look and see if it works
    – Sohail
    Commented Oct 24, 2018 at 15:19

5 Answers 5


So as I mentioned in my comment, the proper way to achieve this is to use the Handlers functionality in Webform, for that we need a custom module for our Handler to show up in admin/structure/webform/manage/[WebformName]/handlers

One thing that you need to make sure is correct, is the structure of the module folder, so that webform would read it as a handler, we assume the module name here is: webform_handler_user_creation so the structure would be something like this: webform_handler_user_creation>src>Plugin>WebformHandler>UserCreationHandler.php with a webform_handler_user_creation.info.yml file in the root of the module directory.

With all that said, here's an example of the module on my github page

So what we need to do first is to make sure we do our thing after saving the webform submission, then load the submission values and use them based on their machine names to fill in our user creation thingy, here's the code:

namespace Drupal\webform_handler_user_creation\Plugin\WebformHandler;

use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionInterface;
use Drupal\webform\Entity\WebformSubmission;
 * Webform submission action handler.
 * @WebformHandler(
 *   id = "usercreate",
 *   label = @Translation("User Create"),
 *   category = @Translation("Action"),
 *   description = @Translation("Creates a user after submission"),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 *   submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
 * )

class UserCreationHandler extends WebformHandlerBase {
   * {@inheritdoc}
  public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
        $user = \Drupal\user\Entity\User::create();
        $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
        $user_name = $webform_submission->getElementData('user_name');
        // Mandatory user creation settings
        $user->setEmail('[email protected]');
        $user->setUsername($user_name); // This username must be unique and accept only a-Z,0-9, - _ @ .
        $user->set("langcode", $language);
        // Optional settings
        $user->set("init", 'email');
        $user->set("preferred_langcode", $language);
        $user->set("preferred_admin_langcode", $language);
        // Add a custom role in case you need one
        //Save user


also note the namespace at the beginning of the file, this is where it gets loaded into the administration area of a webform like the following image: enter image description here

Note that in this example we use $user_name as the only field that gets populated dynamically from the webform submission, you have to replace the rest according to your webform fields machine names

  • Thanks for your help so far, this makes it clearer. I'll accept your answer as it has gotten me closest to what I want to do so far. I am however still encountering an issue. I've created a module called researcher_reg in the way you've described however when I go to add the handler to the webform after installing the module the handler doesn't show up. The namespace line in my UserCreationHandler.php file is namespace Drupal\researcher_reg\Plugin\WebformHandler;. Any ideas how I can fix this? Thanks. Commented Oct 29, 2018 at 10:59
  • Thanks for accepting the answer, and Yes the reason that it doesn't show up is that you probably didn't name it! You see that commented section with @WebformHandler? Yeah, that's not really a comment =P, make sure to have it there and clear cache afterwards
    – Sohail
    Commented Oct 29, 2018 at 23:27
  • Thanks, it worked for me as well. For Password : $user->setPassword($pass_word); To make the password drupal specific.
    – Wasim Khan
    Commented Mar 27, 2019 at 5:37

Welcome to Drupal Answers!

If styling is the only concern here, I would strongly recommend not using webform over Drupal's default registration process. You could simply add more fields to the user from account settings and have them displayed while registration. Benefits:

  1. The data remains attached to the user entity even after registration, which means the users' will have the facility to edit the values provided while registration.
  2. You could use them with ease to create the profile pages if intended.
  3. You could use these fields as filters on the users listing page.
  4. Many other cases depending on the site.

As for theming the form, I did a quick search and found some useful links:

  1. Drupal 8: How to theme any form.
  2. Send a form to twig template.
  3. How do I theme a custom form?
  4. Theming form elements in Drupal 8.
There is a module for that.

Forms Steps provides an UI to create forms workflows using forms modes. It creates quick and configurable multisteps forms.

  • Looks like it could work although there is no stable release available. Do you know of an alternative that does the same thing? Commented Oct 15, 2018 at 8:13
  • As of June 2020 there is a stable release with version 1.4
    – yunzen
    Commented Jun 18, 2020 at 8:35

As stated, if possible, you'll have a much easier time using the standard Drupal registration process, rather than trying to create a webform and sync fields with the registration form.

Depending on your site needs / restrictions, you could always "fake" a multi-step form with a custom template. If all of the form fields print out on the same page, you can use the template to split those fields into "sections" and then use JS to let the user step through the full process while staying on the same page.

A great example is provided here - https://www.w3schools.com/howto/howto_js_form_steps.asp - which also includes form validation on the form step buttons, so that users can't skip a required field on Step 1 before moving on to Step 2.

  • Thanks for this, I think it's the best approach. Once I've created the twig template for the form do you know how to render individual form fields? Commented Oct 15, 2018 at 9:09
  • Basics can be found here - drupal.stackexchange.com/questions/220415/… - the example is for the user login form, but should be a good starting point for related forms as well. If you need to get into more specific / custom theming, there's a good walkthrough here: drupal.stackexchange.com/questions/245127/…
    – Lauren G
    Commented Oct 16, 2018 at 16:56

I was able achieve this on multiple Drupal 8 site and could create users on both Drupal & civicrm. I used some custom code to create user in Drupal by taking the submitted values.

Here is a thread but it is old and may have different approach with Drupal 8.6.x


This is about creating users in code after the webform has been submitted. For template, check this: https://www.drupal.org/docs/8/theming/twig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.