Follow-up to #2263569: Bypass form caching by default for forms using #ajax..
There, in RenderElement::preRenderAjaxForm()
we changed the default URL of an AJAX submission from Url::fromRoute('system.ajax')
to Url::fromRoute('<current>')
. Most of the time, this is the same as $form['#action']
, but not always. For example, comment forms sometimes set the action to a separate page.
For the cases where the action is not the current page, let's discuss which one AJAX should submit to, and then add docs and test coverage for that. In most cases, since the AJAX response is built solely out of what's in $form and $form_state at the end of form processing, which route we submit to probably doesn't result in any difference, if both the current route and action route end up calling $form_builder->buildForm() with the same arguments, and if there aren't alter hooks that modify differently based on the route. But, since it is possible to write routes and alter implementations that result in differences, we should take a stance here.
Reasons for AJAX to submit to $form['#action']:
- All #ajax elements fall back to submitting to the form action when JS is disabled, so this would bring more consistency for what server-side form processing code runs, regardless of whether JS is enabled in the browser.
Reasons for AJAX to submit to the current page:
- The purpose of the AJAX response is to update the current page, so shouldn't it do so with content meant for that page? When JS is disabled, an entire new page is returned, so it matters less whether that's the same or different than the current one.