← All writing

PHP dropping form fields? max_input_vars and chunked forms

You submit a large form, PHP receives it, and some of the fields are simply not there. No error on screen, no exception, just missing data. I ran into this on an Interspire store, on a form with a very large number of fields. It's almost always one of two PHP settings.

Suspect 1: max_input_vars

PHP refuses to parse more than max_input_vars variables into $_POST (and separately into $_GET and $_COOKIE). The default is 1,000. Anything past that is silently thrown away, and the only trace is a warning in the error log:

PHP Warning: Unknown: Input variables exceeded 1000.

The giveaway: count($_POST, COUNT_RECURSIVE) comes back at or near 1,000, and it's always the fields at the end of the form that go missing.

Suspect 2: post_max_size

If the whole request body is bigger than post_max_size (8 MB by default), PHP doesn't keep part of it. It drops all of it, and $_POST and $_FILES arrive empty. If every field is missing, this is your limit, not max_input_vars.

The quick fix, and why it's not enough

If you control the server, you can raise the limits in php.ini:

max_input_vars = 5000
post_max_size = 32M

That works until the form grows again, and on shared hosting you often can't change it at all.

The durable fix: send the form in chunks

Keep one button for the user, but have the browser send the fields in parts, each well under the limits, then tell the server to put them together:

async function submitInChunks(form, size = 500) {
  const entries = [...new FormData(form).entries()];
  const token = crypto.randomUUID();
  for (let i = 0; i < entries.length; i += size) {
    const body = new FormData();
    body.append('token', token);
    for (const [name, value] of entries.slice(i, i + size)) body.append(name, value);
    await fetch('/form/part', { method: 'POST', body });
  }
  await fetch('/form/finish', { method: 'POST', body: new URLSearchParams({ token }) });
}

On the server, /form/part adds each chunk to temporary storage (the session or a staging table) under the token, and /form/finish merges the chunks, validates the complete form once, and saves it as a single record. Validating only at the end keeps the behaviour the same as a normal submit.

Sending the form as one JSON body and reading it with json_decode(file_get_contents('php://input')) also avoids max_input_vars, because PHP doesn't parse JSON into $_POST. It doesn't avoid post_max_size, though, so for very large forms chunking is still the safer choice.

The takeaway

When data goes missing without an error, check the limits before the code. And prefer a fix that keeps working as the form grows over one that only buys time.

This came up on a large Interspire store I worked on. If you're stuck on something similar, here's how I can help.