Hi there

When I use this module and also render the login form on the same page,the login form does not work.
I use this code to get the login form and put it in the template

if (\Drupal::currentUser()->isAnonymous()) {
    $form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class) ;
    $variables['login_form'] = $form;
  }

It look like there is a redirect when submitting (see attached image)

Does anyone have any idea why this is not working

Comments

Roderik de Langen created an issue. See original summary.

ojchris’s picture

ho w are declaring the variable in your template?

roderik de langen’s picture

{{ login_form }}

ojchris’s picture

Two things: you are calling the form but not rendering it and rather than confirming anonymity with isAnonymous() we should rather check to see that there is no authenticated user - with is()

Final code:

if (!\Drupal::currentUser()->id()) {
    $form = Drupal::formBuilder()->getForm(Drupal\user\Form\UserLoginForm::class) ; 
    $render = Drupal::service('renderer');
    $variables['login_form'] = $render->renderPlain($form);
  }
roderik de langen’s picture

Thanx for the check. But the rendering actually is not the issue, the form is rendering perfect. Only the submit is not working. It just reloads the page and triggers not submit.

O and btw the isAnonymous checks if the user is uid 0
https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Entity%2...

ojchris’s picture

Oh guess mixed up the question

Yes it confirms uid but isAnonymous did not work for me as the form doesn't even get rendered. Try with my suggested code verbatim, logs in fine at my end.

Update
======
Do you have the registration forms from multiple_registration module and the login form on the same page?

roderik de langen’s picture

yes both forms are on 1 page

gumrol’s picture

Same issue here. I found a fix, although it's a bit clumsy and probably requires more testing.
The multiple_registration_form_alter implementation is a bit heavy-handed I feel - it should be more precise in the forms it's targeting. Having said that, my own 'fix' is just as heavy-handed. I haven't looked into the ramifications of the change I made, although my login block on my multi-registration pages now work.

Where the route is checked and the form altered based on that, I added another check.
Original ~line 205:

if ($route !== NULL && $route->getPath() === '/user/register/{rid}') {

I just added a check for the form_id too:

if ($route !== NULL && $route->getPath() === '/user/register/{rid}' && $form_id == 'user_register_form') {

There may be forms other than the registration form that need to be altered by multiple_registration_form_alter especially because there is a more specific alter later on in the code too: multiple_registration_form_user_register_form_alter.
Or it could be that the whole function could be merged into multiple_registration_form_user_register_form_alter.. either way, it works for me now.

gumrol’s picture

StatusFileSize
new506 bytes

Hopefully someone will get some use out of this patch. It applied cleanly for me on version 2.99.0 and fixes the issue

maddentim’s picture

So the patch from @gumrol #9 does not apply to the latest release 3.1.1 as the line that #9 is changing is changed differently coming from
the issue https://www.drupal.org/project/multiple_registration/issues/3258961
I am hoping that this issue is now a duplicate and the other solution is good to go.

maddentim’s picture

I updated to the patch from #9 to apply to the current 3.1.1 release. This resolves the issue for me.

wombatbuddy’s picture

Status: Active » Needs review
ysamoylenko’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @maddentim and @gumrol
for your effort and module support.

The #11 patch will be committed soon.

ysamoylenko’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.