Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When the modal login block content is fetched from the cache, the form is not generated again. So it does not run through hook_form_alter().
Therefore, the additional ajax parameters, added to $form['#prefix']
, $form['#suffix']
and $form['actions']
in bootstrap_login_modal_form_user_login_alter()
and bootstrap_login_modal_form_user_register_form_alter()
will not get called when the form is retrieved from the cache.
Comment | File | Size | Author |
---|---|---|---|
#2 | caching_prevents_the-2662460-2.patch | 448 bytes | Leon Kessler |
|
Comments
Comment #2
Leon Kessler CreditAttribution: Leon Kessler commentedI can't think of a better way to do this than setting the block to not cache.
We might be able to move everything into
theme_bootstrap_login_modal_output()
, so that it's all stored in the cache.However, the
$form['actions']['submit']['#ajax']
would be difficult, and would have to mimic how Drupal core adds this to the page.Comment #3
2phaThis issue is confusing me.
Are you trying to add stuff in `bootstrap_login_modal_form_user_login_alter()` depending on the page but it getting a cached version?
Just changing it to not cache is not an answer as the module seems to be working fine as is for many sites.
Comment #4
Leon Kessler CreditAttribution: Leon Kessler commentedNope not adding anything to
bootstrap_login_modal_form_user_login_alter()
.The problem is the necessary changes to the form to ensure it runs with ajax are added there, are only run when the cache is cold.
Steps to reproduce:
Visit a new page with the login modal, the form should submit via ajax.
Refresh the page, now re-launch the modal. The form will now submit back to the page, and not via ajax. You can see this by submitting the form with an error, it will not be displayed on the current modal as it should do.
Comment #5
2phaWOW, you are right, how did no one report this before. I suppose they thought it must have just been meant to work that way. Or they didn't test properly, same as me.
Comment #7
2phaHad a look at how the user module handles it's login block and it uses DRUPAL_NO_CACHE, so we'll just go with that then.
Committed DRUPAL_NO_CACHE
Comment #9
2phaComment #10
2pha