Jack Casas
Jack Casas

Reputation: 994

HTML form inputs to PHP Array. Not all values are posted

So I have this form:

<form data-ajax="false" name="frm" action="cmd_go.php" method="post" >
	<input type="hidden" name="cmd" value="insertarlineapedidomultiple">
	<input type="hidden" name="mod" value="yes">
	<!--<input id="insertList" type="hidden" name="insertList" value="">-->
	<input type="hidden" name="o" value="<?php echo $o ?>">
	<div id="div_lista_familias" data-role="collapsibleset" data-content-theme="a" data-iconpos="right">
	</div>
	<input class="insertar btn-azul ui-btn ui-corner-all" data-role="none" type="submit" value="Insertar"/>
</form>

Then we have some Javascript code to populate the form content after calling a web service:

function listaProductos(alb, fam){
    var ok = false;
    $.ajax({
        type: 'GET',
        url: url_servicio + alb + '/' + fam + '/productos',
        dataType: "json", // data type of response
        //async: false,
        error: function(){
            ok = false;
        },
        success: function(data){
            var content;
            var acum = 0;
            for(i=0; i<data.length; i++){
                ok = true;
                var qty = get_item_qty_inline(data[i].itemid);				
				var qty2 = get_item_qty2_inline(data[i].itemid);
				var qty3 = get_item_qty3_inline(data[i].itemid);
                var dto = get_item_dto1_inline(data[i].itemid);
                content = '<fieldset class="ui-grid-d">';
                content += '<div class="ui-block-a"><label for="name">';
                content += data[i].itemid + ' ' + data[i].nombre + '</div>';
                content += '<div class="ui-block-c ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset""><input type="number"'; 
                content += ' name="cantidad[]" pattern="[0-9]*" id="number-pattern"';
                content += ' value="' + qty + '" placeholder="Uds1" onfocus="this.oldvalue = this.value;" onchange="onChangeQty(this); this.oldvalue = this.value;"></div>';
                content += '<div class="ui-block-b ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset""><input type="number" name="dtoporc1[]" pattern="[0-9]*" id="number-pattern"'
                content += ' value="' + dto + '" placeholder="%Dto1"></div>';
                content += '<div class="ui-block-d ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset""><input type="number"'; 
                content += ' name="cantidad2[]" pattern="[0-9]*" id="number-pattern"';
                content += ' value="' + qty2 + '" placeholder="Uds2" onfocus="this.oldvalue = this.value;" onchange="onChangeQty(this); this.oldvalue = this.value;"></div>';
				content += '<div class="ui-block-e ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset""><input type="number"'; 
                content += ' name="cantidad3[]" pattern="[0-9]*" id="number-pattern"';
                content += ' value="' + qty3 + '" placeholder="Uds3" onfocus="this.oldvalue = this.value;" onchange="onChangeQty(this); this.oldvalue = this.value;"></div>';
				content += '<input type="hidden" name="idalbaran[]" value="' + alb +'">';
                content += '<input type="hidden" name="itemid[]" value="' + data[i].itemid +'">';
                content += '<input type="hidden" name="famalbaran[]" value="' + fam +'">';
                content += '<input type="hidden" name="itemdesc[]" value="' + data[i].nombre +'">';
                content += '<input type="hidden" name="precioventa[]" value="' + data[i].precio + '">';
                content += '<input type="hidden" name="dtoporc2[]" value>';
                content += '<input type="hidden" name="dtoporc3[]" value>';
                $('#'+fam.replace(/ /g, '_')+'_content').append(content);
                acum += parseFloat(qty || 0) + parseFloat(qty2 || 0) + parseFloat(qty3 || 0);
                $('#'+fam.replace(/ /g, '_')+' .ui-li-count').html(acum);                
            }
        },
        complete: function(data, status){
            if (!ok){
                $('#'+fam.replace(/ /g, '_')).remove();
            }
        }
    });
}

Finally, this is the PHP code we have in cmd_go.php

//GET variables
 if(isset($_GET)){
  $params = array_keys($_GET);
  for ($i=0;$i<count($params);$i++)
    if(isset($_GET[$params[$i]])){
      $nv=$params[$i];
      $$nv=$_GET[$params[$i]];
   }
 } 

 //POST variables
 if(isset($_POST)){
  $params = array_keys($_POST);
  for($i=0;$i<count($params);$i++)
    if(isset($_POST[$params[$i]])){
      $nv=$params[$i];
      $$nv=$_POST[$params[$i]];
      //print "$nv : ".$$nv.'<br />';
   }
 }
 var_dump($itemid);

The problem is that not all values are posted, because our $itemid array only has 91 elements, when our web service returns about 400. Out HTML form is correctly displayed with all 400 items, but out PHP var_dump returns:

array(91){[0]=>string(6) "173771" [1]=>string(6) "173772" [2]=>string(6) "564814"...[90]=>string(6) "548115"}

Any ideas on why POST could be taking only 91 records??

Upvotes: 0

Views: 703

Answers (1)

Andrey Yerokhin
Andrey Yerokhin

Reputation: 273

You need to check max_input_vars value in php.ini. It can lead to such behavior.

http://php.net/manual/en/info.configuration.php#ini.max-input-vars

Upvotes: 2

Related Questions