HTML表单输入到PHP数组。并非所有值都已发布

时间:2017-12-01 11:03:20

标签: php html arrays post

所以我有这样的表格:



<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>
&#13;
&#13;
&#13;

然后我们有一些Javascript代码在调用Web服务后填充表单内容:

&#13;
&#13;
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();
            }
        }
    });
}
&#13;
&#13;
&#13;

最后,这是我们在cmd_go.php中的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);

问题在于并非所有值都被发布,因为我们的$itemid数组只有91个元素,当我们的Web服务返回大约400个时。输出HTML表单正确显示所有400个项目,但不包括PHP {{ 1}}返回:

var_dump

关于为什么array(91){[0]=>string(6) "173771" [1]=>string(6) "173772" [2]=>string(6) "564814"...[90]=>string(6) "548115"} 只能获取91条记录的任何想法?

1 个答案:

答案 0 :(得分:2)

您需要检查php.ini中的 max_input_vars 值。它可能导致这种行为。

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