So i'm trying to submit a form using ajax, in my form i have the following:

        $form['actions']['#type'] = 'actions';
        $form['actions']['submit'] = array(
        '#type' => 'submit',
        '#value' => $this->t('OK'),
        '#button_type' => 'primary',
        '#prefix' => '<div class="tc btn_pay relative">',
        '#suffix' => '</div>
        '#attributes' => array(
            'class' => array('proximabold', 'tc', 'transition', 'no-underline', 'ph3', 'pv2', 'mb2', 'dib', 'white'),
        '#ajax' => [
            'event' => 'click',
            'callback' => '::updateTable',
            'wrapper' => 'table-wrapper',
            'progress' => [
                'type' => 'throbber',
                'message' => t('Verifying entry...'),

and a simple updateTable function:

public function updateTable(array $form, FormStateInterface $form_state) {
    return "Hello World";

But when i click on submit i get the error: An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports.

I knew that the error is server side (Maybe i'm wrong), so i went to php.ini (i use PHP7) and update the following lines:

post_max_size = 6144M
memory_limit = 6144M
upload_max_filesize = 6144M
max_file_uploads = 1000

but without luck, this configuration shouldn't be necessary as the request size is only 1.5KB

  • i found that the mod_security module create some obstacles for ajax submission but i don't even have the latter installed!! – Abouhassane Abdelhamid Nov 12 '17 at 17:38

So after a throughout debugging i finally found the solution. the first thing i did is that i searched for the error and it was outputed from core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php :: wihtin we find a condition that interests us:

if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
  $this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
  $response = new AjaxResponse();
  $status_messages = ['#type' => 'status_messages'];
  $response->addCommand(new ReplaceCommand(NULL, $status_messages));
  $response->headers->set('X-Status-Code', 200);

So the error is triggered if an exception instanciated of the BrokenPostRequestException class has occurred.

and now if we got to Core/lib/Drupal/Core/Form/FormBuilder.php we find that this exception is thrown if the post request is bigger than what is allowed by the server and also if the request doesn't carry the form id.

if ($ajax_form_request && !$request->request->has('form_id')) {
  throw new BrokenPostRequestException($this->getFileUploadMaxSize());

It would have been better if there was another exception for this case rather than getting the same error for when the post request exceeds the configured allowed size (post_max_size)

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.

So what i did is i added the lines highlited bellow:

<div class="fr relative filtrehold">
        <div class="filtr_btn  br-pill shadow-2 ttu dark-gray f5 proximabold">Filtres</div>
        <form> //Added this one
            {{ McRefund_build_data.filterform.form_build_id }} //Added this one
            {{ McRefund_build_data.filterform.form_id }} //Added this one
            {{ McRefund_build_data.filterform.RelevesMensuels }}
            {{ McRefund_build_data.filterform.from }}
            {{ McRefund_build_data.filterform.to }}
            {{ McRefund_build_data.filterform.example_select }}
            {{ McRefund_build_data.filterform.actions.submit }}
        </form> //Added this one
<div class="table_hold bg-white br2">

    <div id="table-wrapper">

        {% for Num_refund,refund in McRefund_build_data.filterform.RefundsContainer['Refunds']['#Refunds_data'] %}
        {% endfor %}
  • This was super helpful. Just ran in to this. Thank you! – Steve Oliver Mar 13 '18 at 3:13
  • 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. – Steve Oliver Mar 13 '18 at 3:25
  • Great job @SteveOliver, glad it helped :D – Abouhassane Abdelhamid Mar 21 '18 at 9:43
  • FYI: on my side, it was the opposite=> My themed form was containing the <form...> tag. But as it was inside an inline entity form I got this problem. Removing this tag solved it. – Baud Apr 20 at 15:21

Due to an identical error message ("An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size that this server supports")in a project based on Drupal 8, I just discovered a third use of the same exception discussed above. In my case, the exception was thrown by reaching limit of allowed variables in the php.ini file.

  1. Open the file -> vim /etc/php/7.2/apache2/php.ini
  2. Locate the line -> /max_input_vars/n
  3. Uncomment the line and put -> max_input_vars = 3000
  4. Restart Apache -> sudo /etc/init.d/apache2 restart

max_input_vars in php.ini

My two Cents.

  • Thank you! I was running into this error on a Webform with 300 options. Increasing max_input_vars fixed the error for me. I'm also on Acquia so I had to increase it via the Acquia dashboard as described here: support.acquia.com/hc/en-us/articles/… – maskedjellybean yesterday

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.