php - Workaround for 'max_input_vars' limit -


currently i'm working on large form dynamic number of input fields, can extremely large (above 3k variables or more) , causes problems 'max_input_vars' option. i'm looking workaround issue (i'm not interested in increasing value of 'max_input_vars' option), i'm trying join form fields values single field (using jquery serialize() method) , recreate variables on server side. have far:

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>workaround max_input_vars</title>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> </head> <body> <?php if($_server["request_method"]==="post" && !empty($_post["data"])) {     $vars = explode("&", $_post["data"]);     $data = array();     foreach($vars $var) {         parse_str($var, $variable);         assign_var($_post, $variable);     }     echo "<pre>";     var_dump($_post);     echo "</pre>"; } function assign_var(&$target, $var) {     $key = key($var);     if(is_array($var[$key]))          assign_var($target[$key], $var[$key]);     else {         if($key==0)             $target[] = $var[$key];         else             $target[$key] = $var[$key];     }    } ?>       <form id="myform" method="post">         <input type="text" name="var_1" value="<?php echo htmlentities("double quote: \"hello\"");?>"/><br/>         <input type="text" name="var_2" value="<?php echo htmlentities("single quote: 'hello'");?>"/><br/>         <input type="text" name="var_3" value="<?php echo htmlentities("text & ampersant");?>"/><br/>         <input type="text" name="var_4" value="<?php echo htmlentities("animals");?>"/><br/>         <input type="text" name="matrix[]" value="1"/><br/>         <input type="text" name="matrix[]" value="2"/><br/>         <input type="text" name="matrix[]" value="3"/><br/>         <input type="text" name="matrix[]" value="4"/><br/>         <input type="text" name="matrix[]" value="5"/><br/>         <input type="text" name="matrix[]" value="6"/><br/>         <input type="text" name="matrix[]" value="7"/><br/>         <input type="text" name="var_5" value="abc"/><br/>         <input type="text" name="var_6" value="bcd"/><br/>         <input type="text" name="var_7" value="cde"/><br/>         <input type="text" name="var_8" value="def"/><br/>         <input type="text" name="multi_matrix[colors][]" value="red"/><br/>         <input type="text" name="multi_matrix[colors][]" value="blue"/><br/>         <input type="text" name="multi_matrix[colors][]" value="green"/><br/>         <input type="text" name="multi_matrix[weight][]" value="75"/><br/>         <input type="text" name="multi_matrix[weight][]" value="83"/><br/>         <input type="text" name="multi_matrix[weight][]" value="62"/><br/>         <input type="text" name="multi_matrix[height][]" value="170"/><br/>         <input type="submit" value="send">     </form>     <style>     input {         margin: 5px 0;     }     </style>     <script type="text/javascript">     (function(){         $(function(){             $("#myform").submit(function(event) {                 var $this = $(this);                 var data = $this.serialize();                 $this.find("input, textarea, select, button").remove();                 $this.append("<input type='hidden' class='data' name='data'/>");                 $this.find("input.data").val(data);             });         });     })(jquery);     </script> </body> </html> 

as can see, i'm intercepting submit event , replace form fields single 'data' field. on php side i'm using explode() , pars_str() methods recreate variable, lastly want put variable $_post array, created simple recursive function can handle simple values , multidimensional associative arrays. result $_post array filled form values, if form submitted normally.

what think above method ? maybe there's simpler solution problem hadn't noticed earlier ? if not, there options improve above code ? there negative side effects of above solution ?

thanks in advance !


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -