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

danielbeeke created an issue. See original summary.

swentel’s picture

Issue summary: View changes

Yeah, 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.

mitchalbert’s picture

I 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)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

flutterstack’s picture

I 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' => '

',
];
}
}

ajits’s picture

Priority: Normal » Major
Issue tags: -ajax pager
StatusFileSize
new245.32 KB

I 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:

ajits’s picture

The buildForm function in FormBuilder class throws the BrokenPostRequestException without checking the post_max_size or upload_max_filesize which 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.AjaxError error in console with the following message:

"
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /en/search/list?ajax_form=1
StatusText: OK
ResponseText: 
| SiteName
Skip to main content
Toolbar items
Back to site
Manage
Administration menuContentStructureAppearanceExtendConfigurationPeopleReportsHelp      
Shortcuts
User-defined shortcutsEdit shortcuts      
Edit
admin
User account actionsView profileEdit profileLog out      
Devel
Development menuCache clearConfig editorContainer InfoCurrent route infoDevel settingsElement InfoEntity InfoEvents InfoExecute PHPField InfoPHPinfo()Rebuild MenuReinstall ModulesRoutes InfoRun cronState editorTheme registryView SessionConfigure      
User account menu
Show — User account menu
Hide — User account menu
My account
Log out
SiteName
Breadcrumb
Home
Search
qwerqwer  
Select ratingGive it 1/5Give it 2/5Give it 3/5Give it 4/5Give it 5/5Cancel rating
Product fdsadfas  
Select ratingGive it 1/5Give it 2/5Give it 3/5Give it 4/5Give it 5/5Cancel rating
product asdfsub title  
Select ratingGive it 1/5Give it 2/5Give it 3/5Give it 4/5Give it 5/5Cancel rating
- Any -
Product
Treatment
Categories
- Any -
Body
Face
Sun
Powered by Drupal
{"ajaxPageState":{"theme":"bartik","libraries":"bartik\/global-styling,bartik\/global-styling,classy\/base,classy\/base,contextual\/drupal.contextual-links,contextual\/drupal.contextual-links,contextual\/drupal.contextual-toolbar,contextual\/drupal.contextual-toolbar,core\/drupal.active-link,core\/drupal.active-link,core\/drupal.states,core\/drupal.states,core\/html5shiv,core\/html5shiv,core\/normalize,core\/normalize,devel\/devel-toolbar,devel\/devel-toolbar,fivestar\/fivestar.base,fivestar\/fivestar.base,fivestar\/fivestar.craft,fivestar\/fivestar.craft,quickedit\/quickedit,quickedit\/quickedit,shortcut\/drupal.shortcut,shortcut\/drupal.shortcut,system\/base,system\/base,toolbar\/toolbar,toolbar\/toolbar,toolbar\/toolbar.escapeAdmin,toolbar\/toolbar.escapeAdmin,user\/drupal.user.icons,user\/drupal.user.icons,views\/views.ajax,views\/views.ajax,views\/views.module,views\/views.module"},"ajaxTrustedUrl":{"\/en\/search\/list":true,"\/en\/search\/list?ajax_form=1\u0026_wrapper_format=html":true},"ajax":{"edit-category-3--cax4Rt4a8zc":{"callback":"\\Drupal\\custom_module\\Form\\DependentFieldOptionsUpdater::updateOptions","wrapper":"dependent-fields-wrapper-container","event":"change","url":"\/en\/search\/list?ajax_form=1\u0026_wrapper_format=html","dialogType":"ajax","submit":{"_triggering_element_name":"category"}},"edit-category-2--9GYwZXePFM4":{"callback":"\\Drupal\\custom_module\\Form\\DependentFieldOptionsUpdater::updateOptions","wrapper":"dependent-fields-wrapper-container","event":"change","url":"\/en\/search\/list?ajax_form=1\u0026_wrapper_format=html","dialogType":"ajax","submit":{"_triggering_element_name":"category"}},"edit-category-1--0v2QWtzowdM":{"callback":"\\Drupal\\custom_module\\Form\\DependentFieldOptionsUpdater::updateOptions","wrapper":"dependent-fields-wrapper-container","event":"change","url":"\/en\/search\/list?ajax_form=1\u0026_wrapper_format=html","dialogType":"ajax","submit":{"_triggering_element_name":"category"}},"edit-category-all--znJmZTHUY7M":{"callback":"\\Drupal\\custom_module\\Form\\DependentFieldOptionsUpdater::updateOptions","wrapper":"dependent-fields-wrapper-container","event":"change","url":"\/en\/search\/list?ajax_form=1\u0026_wrapper_format=html","dialogType":"ajax","submit":{"_triggering_element_name":"category"}}},"views":{"ajax_path":"\/en\/views\/ajax","ajaxViews":{"views_dom_id:61a824844ea9e7826a772e4d0f0688f35653a3386ea8ff57c6605c3eb4679679":{"view_name":"product","view_display_id":"page_1","view_args":"","view_path":"\/en\/search\/list","view_base_path":"search\/list","view_dom_id":"61a824844ea9e7826a772e4d0f0688f35653a3386ea8ff57c6605c3eb4679679","pager_element":0}}},"toolbar":{"breakpoints":{"toolbar.narrow":"only screen and (min-width: 16.5em)","toolbar.standard":"only screen and (min-width: 38.125em)","toolbar.wide":"only screen and (min-width: 61em)"},"subtreesHash":"syiNQBqkuhiTAFEphKRff4vm1Jn6qd5SEPshNLAEWwg"},"path":{"baseUrl":"\/","pathPrefix":"en\/","currentPath":"search\/list","currentPathIsAdmin":false,"isFront":false,"currentLanguage":"en","currentQuery":{"_wrapper_format":"html","ajax_form":"1"}},"pluralDelimiter":"\u0003","user":{"uid":"1","permissionsHash":"1b376d1403b56ce9f0c75b7faa8c09318a30c46bf4a494de4d495238f11cc4e4"}}
"
ajits’s picture

Title: Allowed post_max_size check is invalid. Pager inside a custom ajax form » Custom form AJAX error of upload file size shown even with no file field.

Changing the title. This is not limited to pager. This is the best I could come up with.

ajits’s picture

JS callstack below:

	Drupal.Ajax.error	@	ajax.js?v=8.3.2:965
complete	@	ajax.js?v=8.3.2:510
t.complete	@	jquery.form.min.js?v=3.51:11
i	@	jquery.min.js?v=2.2.4:2
fireWith	@	jquery.min.js?v=2.2.4:2
z	@	jquery.min.js?v=2.2.4:4
(anonymous)	@	jquery.min.js?v=2.2.4:4
XMLHttpRequest.send (async)		
send	@	jquery.min.js?v=2.2.4:4
ajax	@	jquery.min.js?v=2.2.4:4
e.fn.ajaxSubmit	@	jquery.form.min.js?v=3.51:11
Drupal.Ajax.eventResponse	@	ajax.js?v=8.3.2:679
(anonymous)	@	ajax.js?v=8.3.2:536
dispatch	@	jquery.min.js?v=2.2.4:3
r.handle	@	jquery.min.js?v=2.2.4:3
trigdog’s picture

I 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

edurenye’s picture

I 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.

edurenye’s picture

Status: Active » Needs review
StatusFileSize
new768 bytes

Done.

Status: Needs review » Needs work

The last submitted patch, 15: custom_form_ajax_error-2658718-15.patch, failed testing. View results

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new790 bytes

Ups, now should work.

edurenye’s picture

StatusFileSize
new1.26 KB

Sorry, this time I really tested it.

The last submitted patch, 17: custom_form_ajax_error-2658718-17.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 18: custom_form_ajax_error-2658718-18.patch, failed testing. View results

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

steveoliver’s picture

From https://drupal.stackexchange.com/questions/250078/ajax-submission-leads-...,

My problem: I was adding a 'destination' parameter to the url of the ajax link that opened my custom form, and used the destination in my submit handler, to issue a form redirect, causing the redirect to appear to be an ajax request in /Drupal/Core/Form/FormBuilder.php:299, but without the form_id (since it was in fact a GET (redirect)), and thus exploded with that misleading upload file size error.

My solution: Remove the destination parameter from the ajax link, so as not to confuse the ajax handling of the form builder on the redirect; and handle the redirect a different way.

goz’s picture

I 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.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kpv’s picture

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

joachim’s picture

Closed 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.

ajv009’s picture

So 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!

ajv009’s picture

my stack trace looks like this ->

Drupal.Ajax.error	@	ajax.js?v=8.9.13:507
complete	@	ajax.js?v=8.9.13:241
t.complete	@	jquery.form.js:298
c	@	jquery.min.js?v=3.5.1:2
fireWith	@	jquery.min.js?v=3.5.1:2
l	@	jquery.min.js?v=3.5.1:2
(anonymous)	@	jquery.min.js?v=3.5.1:2
load (async)		
send	@	jquery.min.js?v=3.5.1:2
ajax	@	jquery.min.js?v=3.5.1:2
(anonymous)	@	jquery.form.js:437
e.fn.ajaxSubmit	@	jquery.form.js:437
Drupal.Ajax.eventResponse	@	ajax.js?v=8.9.13:333
(anonymous)	@	ajax.js?v=8.9.13:272
dispatch	@	jquery.min.js?v=3.5.1:2
v.handle	@	jquery.min.js?v=3.5.1:2
trigger	@	jquery.min.js?v=3.5.1:2
a.event.trigger	@	jquery-migrate.min.js?v=8.9.13:2
(anonymous)	@	jquery.min.js?v=3.5.1:2
each	@	jquery.min.js?v=3.5.1:2
each	@	jquery.min.js?v=3.5.1:2
trigger	@	jquery.min.js?v=3.5.1:2
triggerUploadButton	@	file.js?v=8.9.13:95
dispatch	@	jquery.min.js?v=3.5.1:2
v.handle	@	jquery.min.js?v=3.5.1:2

Any fixes?

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
ndf’s picture

What joachim says in https://www.drupal.org/project/drupal/issues/2658718#comment-13783185

This error comes up if you're outputting a form in a Twig template and you've rendered individual form element.

And Abouhassane Abdelhamid on StackOverflow https://drupal.stackexchange.com/a/250149/16345 says

well in my case it was not a matter of post size request but rather when I themed the form in my twig file, I did not include the form id.

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.twig
https://git.drupalcode.org/project/commerce/-/blob/8.x-2.x/modules/check...

<div class="layout-checkout-form clearfix">
  <div class="layout-region layout-region-checkout-main">
    {{ form|without('sidebar', 'actions') }}
  </div>
  <div class="layout-region layout-region-checkout-secondary">
    <h3>{% trans %} Order Summary {% endtrans %}</h3>
    {{ form.sidebar }}
  </div>
  <div class="layout-region layout-region-checkout-footer">
    {{ form.actions }}
  </div>
</div>

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.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

infojunkie’s picture

I'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.url property to include the form_id:

/**
* Implements hook_form_FORM_ID_alter() for views_exposed_form.
*/
function my_module_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {

      $uri = \Drupal\Component\Utility\UrlHelper::parse(\Drupal::request()->getRequestUri());
      $uri['query']['form_id'] = $form['#id'];
      $uri['query']['ajax_form'] = 1;
      $form['term_node_tid_depth']['#ajax'] = [
        'callback' => 'my_module_callback',
        'wrapper' => 'wrapper-container',
        'url' => Url::fromUri('internal:' . $uri['path']),
        'options' => ['query' => $uri['query'], 'fragment' => $uri['fragment']]
      ];

}

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.