How many $ _POST records of a form with dynamic input? [duplicate]

5

I have a form with dynamic fields but I noticed that when I send it it limits to 166 records.

In my form the fields are within a WHILE like this:

<input name="contagem[]" type="hidden" value="<?php echo $contagem; ?>" />
<input name="data_pgto[]" type="hidden" value="<?php echo $row['data_pgto']; ?>" />
<input name="descricao[]" type="hidden" value="<?php echo $row['descricao']; ?>" />

I'm capturing POST like this:

  $quant_linhas = count($_POST['contagem']);
     for($i = 0; $i < $quant_linhas; $i++){

         $pgt = $data_pgto[$i];
         $ds = $descricao[$i];
         echo "Data:".$pgt." - Descrição:".$ds."<br>";
     }

The form is fed from SQL and has 380 records but when I send the POST it will only 166

    
asked by anonymous 23.11.2016 / 04:49

1 answer

7

Check the max_input_vars directive.

If you are really sure that there are even more than 300 fields in the form and always arrive as a limit of 166, the most likely hypothesis is limitation in the configuration directive max_input_vars . The default is 1000 but your environment may be set to 165/166.

Normally when you pass the limit, the limit + 1 (1001) is returned. If in your case shows 166, it is probably 165. But I can not say.

Note that it is not allowed to modify at runtime with ini_set() . But it can be modified if you set custom configuration files with PHP_INI_PERDIR . It will still not be able to change at runtime, but at least it will not change globally.

Obviously, after all, make sure that there are actually 380 records. Note that there are 3 of each (based on what you posted in the question). So it would have 1140 fields and this in itself would already burst the default installation limit.

Depending on the configuration of the environment, the request is interrupted by the web server. Here's an example with Apache 2.4.20, Windows 10, Chrome:

Ididatestthatpassedthevalueofmax_input_varsanddidnotevenenterthePHPexecutiontocounthowmanywerereceived.Thechromereturnsthisscreenabove.ERR_CONTENT_DECODING_FAILED.

ThetestwasdonewithPHP5.6andPHP7.Bothreturnthesameresult.

  

It's1000even,butoneachlineIhave6inputs.

Ifyouhave380recordsandeachrecordgenerates6fields,thentheformmusthave2280fields.Thisexceedsthestandardlimitof1000.Butherewecansaythatthereisaninconsistency.Ifyouwereactuallysendingthe2280,theresultonthereceiptwouldbe1000or1001oreventheERR_CONTENT_DECODING_FAILEDerror.Alsonotethatthismaydependonyourenvironment.

Toclearthedoubt,makesurethattheformactuallycontainsthe2280fields.ForthisyoucanuseJavaScript.

Intheform,defineanid.Example:<formid="frm" action...

<script>
frm = document.getElementById("frm"); // frm é o id do formulário
console.log(frm.elements.length); // no console log do seu browser exibirá a quantidade de elementos desse formulário.
</script>

Particularly I believe there are some errors in the form. It's apparently not generating all the fields as expected. The reason is very obvious. If it was the PHP configuration limit, it would be cut in 1000 instead of 166. What's more, in a test-like environment I used, the decode error would be displayed. There are conflicts in what you have described. Take the test with JavaScript.

    
23.11.2016 / 05:08