I am trying to place the login form next to the registration form (actually in a modal; but not relevant). I have a template suggestion in my .theme file to allow templating the registration form:

function mytheme_theme(&$existing, $type, $theme, $path) {
  $hooks['user_register_form'] = [
    'template' => 'user/user-register-form',
    'render element' => 'form',
  return $hooks;

and then i preprocess the registration form and embed the login form with idea from here: Render login Form

function mytheme_preprocess_user_register_form(&$variables) {
  $variables['register'] = \Drupal::service('renderer')

  $form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class) ;
  $render = Drupal::service('renderer');
  $variables['login'] = $render->renderRoot($form);

And then a twig tpl file with the variables {{register}} and {{login}}.

This all displays perfectly (even the modal); but, when I submit the login form; it complains about required fields on the registration form.

Looking at the HTML I think that makes sense as I can see the structure is:

[form registration] [form login] [/form] [/form]

as opposed to the registration form followed by the login form.

What have I done wrong?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.