The file Drupal\Core\Form\FormBuilder has a very strange check in buildForm.
// In case the post request exceeds the configured allowed size
// (post_max_size), the post request is potentially broken. Add some
// protection against that and at the same time have a nice error message.
if ($ajax_form_request && !isgeweestset($form_state->getUserInput()['form_id'])) {
throw new BrokenPostRequestException($this->getFileUploadMaxSize());
}
This breaks pagers inside custom ajax forms.
The check seems wrong in my opinion, it doesn't check the size of the request. It checks if there is a form_id.
Here you can view the bug in production.
https://www.youtube.com/watch?v=BHbUZJbi4V0
Steps to reproduce:
- Create a custom form, use ajax and pager_default_initialize
- Trigger an ajax call
- Pager links are not totaly fine (sometimes duplicated query args)
- Click on one of the pager links
Comments
Comment #2
swentel commentedYeah, I've see this failure as well being thrown on various occasions when there's no file upload. It's totally confusing when you get this.
Comment #3
mitchalbert commentedI got the same issue,
Got a view with a node form on it. When uploading a file in the nodeform,it gives me a error about filesizes(even if the file is within the filesize)
Comment #7
flutterstack commentedI am also facing same issue.
In node form alter i have attached the #ajax . I am getting "The uploaded file likely exceeded the maximum file size " error. My functionality no where related to file upload.
$form['field_partial_amount']['widget']['0']['#ajax'] = [
'callback' => '\Drupal\my_module\Controller\AjaxCallbackController::responseCallback',
// 'callback' => 'finalWithdrawAmountAjaxTest',
'wrapper' => 'final-balance',
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => NULL,
],
];
below is my AjaxCallbackController.php
namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* call back controller class
*/
class AjaxCallbackController extends ControllerBase {
/**
* @return rennderable array
*
*/
static function responseCallback(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
return $response = [
'#markup' => '
',
];
}
}
Comment #8
ajitsI was also able to reproduce the error at my end.
Steps I took:
1) Alter views_exposed_form.
2) Add
'#ajax'to the select form element with a'callback'function and a'wrapper'id.3) Whenever I change the value of this element. I get this error. Please see the image below:
Comment #9
ajitsThe
buildFormfunction inFormBuilderclass throws theBrokenPostRequestExceptionwithout checking thepost_max_sizeorupload_max_filesizewhich seems to be incorrect.I commented out the line which throws the exception, and tried to change the values again. The control doesn't seem to go into the callback function. Instead I get the
Drupal.AjaxErrorerror in console with the following message:Comment #10
ajitsChanging the title. This is not limited to pager. This is the best I could come up with.
Comment #11
ajitsJS callstack below:
Comment #12
trigdog commentedI was also getting this. I finally figured out that had something to do with the custom template I was using for my form declared in a hook_theme function. Once I removed that, it started working. My template was pretty simple but I have yet to figure out anything past that it had to do with using a template file with my form.
Update:
Just coming back to this. Simple mistake on my part. My template was missing: {{ form.form_id }}. Once I fixed this, everything worked just fine.
Unfortunately, the "file size" error message is really misleading, confusing, and definitely made it hard to track down my simple mistake especially since my form has nothing to do with a file field.
Comment #14
edurenye commentedI have this issue also when I render a view with a pager inside a form, when I change the page the response contains this error, also in the preview of the view that appears when you edit the view.
Comment #15
edurenye commentedDone.
Comment #17
edurenye commentedUps, now should work.
Comment #18
edurenye commentedSorry, this time I really tested it.
Comment #22
steveoliver commentedFrom https://drupal.stackexchange.com/questions/250078/ajax-submission-leads-...,
Comment #23
goz commentedI have the same issue. The patch does not fix anything. Worst, it's break others.
In my case, i have this issue when varnish cache POST requests. By default, my varnish configuration cached POST requests. Configuring varnish to pass POST requests fixed this issue.
In case you also use varnish and you really want to cache POST requests, maybe you should at least pass ajax form POST requests.
Comment #25
kpv commentedComment #28
joachim commentedClosed https://www.drupal.org/project/drupal/issues/3150306 as a duplicate.
This error comes up if you're outputting a form in a Twig template and you've rendered individual form element.
Comment #29
ajv009 commentedSo what is the solution?
I have a block builder which displays block through twig! And all my forms displayed through its twig isn't working! please help!
Comment #30
ajv009 commentedmy stack trace looks like this ->
Any fixes?
Comment #33
ndf commentedWhat joachim says in https://www.drupal.org/project/drupal/issues/2658718#comment-13783185
And Abouhassane Abdelhamid on StackOverflow https://drupal.stackexchange.com/a/250149/16345 says
That helped me a lot for bugfixing a similar casus on a project. This is a solution:
When rendering individual form elements you should use
{{ form|without( ... ) }}in your twig template. After doing this 'invisible' things required for AJAX will be rendered.Here an example from Drupal commerce
commerce-checkout-form--with-sidebar.html.twighttps://git.drupalcode.org/project/commerce/-/blob/8.x-2.x/modules/check...
Please notice that
{{ form|without('sidebar', 'actions') }}renders everything except the individual elements.Then after that (not sure if order is important though) the individual elements
{{ form.sidebar }}and{{ form.actions }}are rendered.Comment #37
infojunkieI'll just post my own solution here, hope it can help someone.
I'm on Drupal 10, and not using a custom twig file. Still getting this error when attaching an #ajax behaviour to a form element.
I ended up manually setting the
#ajax.urlproperty to include theform_id: