PHP error guide

max_input_vars truncates form data: meaning and fix

Error summary

Reduce unbounded form fields or set a measured site-specific limit, then verify the server receives every required key.

What it means

Reduce unbounded form fields or set a measured site-specific limit, then verify the server receives every required key.

What the error means

PHP stops registering additional GET, POST, or cookie variables after max_input_vars, leaving a partial request array.

Why PHP produces it

The request contains more nested or repeated input variables than the effective per-request protection allows.

PHP version notes

The behavior described for max_input_vars truncates form data applies to PHP 7.4–8.4 unless a narrower version is stated; exact wording can vary by SAPI and patch release.

Most common causes

  • A large settings form generates thousands of fields.
  • Nested names expand into more variables than expected.
  • The warning is hidden and partial data is saved.

Minimal examples

BAD — reproduces the problem

php
saveAll($_POST["items"] ?? []);

FIXED — safer pattern

php
if (count($items) !== $expected) { throw new RuntimeException("Incomplete form"); }

Step-by-step diagnosis

  1. Count submitted successful controls and compare with max_input_vars.
  2. Inspect the end of the expected key sequence in $_POST.
  3. Confirm the effective directive in the web SAPI.

Fixes

Bound the form and reject partial submissions

Paginate or batch large editors and use a completeness token or expected count.

php
if ((int) ($_POST["expected_count"] ?? -1) !== count($_POST["items"] ?? [])) {
    throw new RuntimeException("Incomplete form submission");
}

Common mistakes when fixing it

  • Blindly setting max_input_vars to an enormous value.
  • Saving the partial array.
  • Testing only short forms.

How to prevent it

  • Design bounded or paginated bulk forms.
  • Include and validate expected item counts.
  • Monitor input-variable warnings.

Web server / environment notes

fpm, apache, shared-hosting. Truncation occurs during request parsing before application validation.

Tags: fpm,apache,shared-hosting

Categories