Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Nicholas Mejia
23,800 PointsLaravel - Number of input variables won't accept indicated amount
I'm writing an order form application for internal use at my work and have hit a big snag: We have around 2500 different items that can be ordered but when I generate unique names for each of the inputs and use Input::get() to grab em, it only pulls values for the first 982 values or so. I have already gone into my php.ini file in my vagrant box and set the following settings to max: max_execution_time = 1000 max_input_time = -1 max_input_vars = 10000 memory_limit = 1024M With these new settings added, it increased the amount of inputs selected to the one I listed above (982) so I know it affected some change but nowhere near enough. Here is the code I use to generate my inputs, select the relevant data and filter out blank fields:
This is the controller for creating the form
public function create()
{
$tables = DB::table('categories')->get();
$table_count = count($tables);
$items = array();
$count = 0;
foreach($tables as $category){
array_push($items, DB::table($category->table)->get());
}
Session::put('items',$items);
return View::make('orders.form')
->withTables($tables)
->withItems($items)
->withCount($count)
->withTable_count($table_count);
}
This is the blade function for creating the HTML
@foreach($tables as $category)
<div class="row panel category" id="{{{ $category->table }}}-tab">
<div class="row panel item-selections">
<label for="{{{ $category->table }}}-click" id="{{{ $category->table }}}">{{{ ucfirst($category->name) }}}</label>
<table class="large-12 columns table" id="{{{ $category->table }}}-click">
<thead>
<tr>
<th>Item Number</th>
<th>Description</th>
<th>Qty</th>
</tr>
</thead>
@for($i = 0; $i < count($items[$c]); $i++)
<tr>
<td>{{{ $items[$c][$i]->id }}}</td>
<td>{{{ $items[$c][$i]->description }}}</td>
<td><input type="text" name="{{{ $items[$c][$i]->id }}}"></td>
</tr>
@endfor
</table>
</div>
</div>
<?php $c++; ?>
@endforeach
Finally, here is the part of the controller that grabs each item input and removes any blank items from the array
foreach($items as $array_pos => $array2){
$num_of_rows = count($items[$array_pos]);
for($i = 0;$i < $num_of_rows;$i++){
if(Input::get($items[$array_pos][$i]->id) != ''){
$items[$array_pos][$i]->qty = Input::get($items[$array_pos][$i]->id);
}
else{
unset($items[$array_pos][$i]);
}
}
}
There are about 7 other inputs on the page for user info but I omitted it as I have no trouble grabbing that data, though I imagine those also count against the max number of input vars allowed. I have already considered separating the inputs onto different pages under the original limit of 1000 for production purposes but I would much prefer to keep it all on one page. Does anyone have any experience with going beyond the limit of 1000 inputs? Any help would be greatly appreciated.
thomascawthorn
22,986 PointsI've researched around your last point re static methods because I find it quite interesting! If you can point me in the direction of where I can find out more, that would be fantastic. From what I've read it makes the code difficult to understand and debug etc and isn't 'OOP'.. but if it works once, it should work again? So in this scenario where it's working for a large number of the results, it should work for all of them? Unless it takes up more memory than alternative OOP methods, and this stops the process short of completion?
Justin Black
24,793 PointsYou'd be correct that if it works once it should work again. ( I threw in the last part specifically because I really dislike Laravel because of it's over use of static methods and variables ). However, in the post, there is no mention of it working properly on other queries.
But, my best guess is that there is an issue with the table in the database for this. In that perhaps there really are only 982 entries in the database... Be important to see the result of dumping out the results of $count. As if $count shows 2500 or anything higher, then it's an issue with the for loop itself.
1 Answer
Nicholas Mejia
23,800 PointsThanks guys, I figured it out. It was never a database issue. I could successfully generate all the inputs from every item in the DB but again, the problem was that when I tried passing the input via POST, it was only pulling a max of 1000 inputs.
Turns out I was editing the wrong php.ini file in my vagrant box. Once I changed the max_input_var to over 1000, everything worked perfectly. If anyone is still following this thread, would you know if modifying the max_input_var in a production setting could open up any potential security holes?
Justin Black
24,793 PointsIf you have to change the max_input_var, your app is horribly designed. Won't necessarily open holes, unless you're using old mysql_* extensions instead of something like PDO or MySQLi. By setting it at 1000, you're essentially saying that you plan to have a single form with 1000 input fields, or query string with 1000 variables, or a cookie with 1000 sub-cookies...
It's a very bad design pattern, but won't open up any security holes -- again unless you are using mysql_* extensions and NOT sanitizing your inputs.
Nicholas Mejia
23,800 PointsI agree with you, I ended up splitting the form over 3 pages as well as storing inputs in a temporary table so that if there is any sort of problem mid order, it saves what you have entered and you are able to complete your order without losing any progress. Since it's in Laravel, everything done with the query builder uses PDO parameter binding so I don't need to worry about sanitizing anything either.
Thanks for the input too :)
Justin Black
24,793 PointsJustin Black
24,793 PointsI'm a symfony guy, but generally speaking this shouldn't be an issue. I imagine laravel has some sort of a developer bar like symfony -- that is where i'd first start...
What happens when you run the query manually? I'm guessing that the problem is in the database and not with configuration of php. i say this, as with PHP straight out of the box -- I successfully traverse a table in an SQL DB with over 20 million rows in it with ease.
I suppose it could also have something to do with Laravel's blatant disregard for standards, and advocating the use of static methods. ( the double colon - or global scope operator )