1

I have a form that uses ajax submit "method", the ajax submit handler returns ajax response with complete form(the form has ajax wrapper outside of itself so no issue there) and it is not working for anonymous users. I am using dynamic_page_cache only at this point.

I am displaying this form via field formatter that I have on an entity(imagine comment form) and I am using lazy builder.

The thing is that the form works for anonymous users if there are multiple forms like this on a single page(imagine taxonomy term page listing entities) but it is not working when there is only one form(entity page..imagine node/1). By not working I mean the form will submit but not with ajax but traditionally via normal post method.

I have checked the form structure, wrapper, drupalSettings.ajax entries, JS errors, watchdog..everything, but I just cannot figure out why the form does not utilize ajax but will submit as normal form instead. I have compared loaded JS with anonymous and logged in user, nothing significant there. The only thing that I have found that differs is missing form_token input in the form compared to logged-in user but I have checked the FormBuilder and this is on purpose + when I'm listing multiple entities with this form the ajax works just fine without it.

And so since there are no errors anywhere I have nothing to grab on to for debugging.

So my question is how could/should I try to debug this issue?

This question is a follow-up from Does caching has to be manually disabled for ajaxified forms?

1

Eureka!

So, I still am not sure what the issue was 100% but I am guessing that there was a name collision with multiple different forms and since Drupal uses name "op" for every submit button since the dark ages of the internet I guess the ajax was trying to get itself applied to the other form that had submit button as well(named op as well) but that did not work of course so that resulted in this weird behavior.

So the way I have fixed this was by setting the #name AND #id attributes on the submit button in my form. I have set the #id which I normally don't do in ajax forms because I would get wrong drupalSettings.ajax entry.

I didn't do this in the first place because the form was working just fine for logged-in users + just fine for anonymous users on entity listings so it didn't made any sense but hey, the more you know.

Your Answer

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