Dynamic Form Limiting to 101 Items

I have a complex form that incorporate multiple wbraganca\dynamicform\DynamicFormWidget

I have an issue where it is limiting the entries to 101 on one (haven’t tested the others). I can make the entry directly into the database, so the db isn’t the issue here. So it has to be my code, but I just can’t seem to see the issue.

In the widget configuration I have

    'limit' => 250,
    'min' => 0,

I also tried removing the ‘limit’, but it made no difference

In my controller I start with

    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        $modelsDrivers = $model->drivers;

and the Count($modelsDrivers) always indicates 101 regardless if I make new additions. So right from the beginning of controller action, I don’t seem to be seeing the new entries.

Can anyone point me in the direction of what I should be looking for? I’m a bit lost as to what could be causing this limitation. I can post whatever code you would like to see (model, …)

Is the dynamic from limiting the entries or you are not getting exact no of records from db?

I’m not sure what I was thinking when I originally posted the code above. Obviously that portion of my code returns 101, but it is the

Model::loadMultiple($modelsDrivers, Yii::$app->request->post());

that return 101 as well, where it should be seeing my addition(s)

The full code block is

$oldDriverIds = ArrayHelper::map($modelsDrivers, 'DriverId', 'DriverId');
$modelsDrivers = Model::createMultipleClientDrivers(ClientsDrivers::class, $modelsDrivers);
Model::loadMultiple($modelsDrivers, Yii::$app->request->post());
$deletedDriverIds = array_diff($oldDriverIds, array_filter(ArrayHelper::map($modelsDrivers, 'DriverId', 'DriverId')));

It as if the loadMultiple isn’t getting the additions?

If I add the record via SQL they do indeed show through the web application, but the second I save the record they are deleted after the 101st one.

The dynamic for has a limit of 250, so that shouldn’t be the issue.

I tested to see what is making it’s way to the Controller for processing using

VarDumper::dump(Yii::$app->request->post('ClientsDrivers'), 10, true);

and I get back

...
    99 => [
        'DriverId' => '42'
        'FirstName' => 'John'
        'LastName' => 'Doe'
        'Cell' => '(666) 666-6666'
        'TruckNo' => '66-81269'
        'Active' => '1'
    ]
    100 => [
        'DriverId' => '153'
    ]
]

An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in D:\home\site\vendor\yiisoft\yii2\helpers\BaseVarDumper.php on line 38. in D:\home\site\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
#0 D:\home\site\vendor\yiisoft\yii2\web\Response.php(339): yii\web\Response->sendHeaders()
#1 D:\home\site\vendor\yiisoft\yii2\web\ErrorHandler.php(136): yii\web\Response->send()
#2 D:\home\site\vendor\yiisoft\yii2\base\ErrorHandler.php(135): yii\web\ErrorHandler->renderException(Object(yii\web\HeadersAlreadySentException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\HeadersAlreadySentException))
#4 {main}
Previous exception:
yii\web\HeadersAlreadySentException: Headers already sent in D:\home\site\vendor\yiisoft\yii2\helpers\BaseVarDumper.php on line 38. in D:\home\site\vendor\yiisoft\yii2\web\Response.php:366
Stack trace:
#0 D:\home\site\vendor\yiisoft\yii2\web\Response.php(339): yii\web\Response->sendHeaders()
#1 D:\home\site\vendor\yiisoft\yii2\base\Application.php(392): yii\web\Response->send()
#2 D:\home\site\wwwroot\admin\index.php(17): yii\base\Application->run()
#3 {main}

How can it process 100 and then suddenly have a HeadersAlreadySentException?

Stab in the dark here, but could my action be timing out?

I’m using the following

$('form#{$model->formName()}').on('beforeSubmit', function(e){
    var \$form = $(this);

    $.post(
        \$form.attr("action"), //serialize Yii2 form 
        \$form.serialize(),
    )
    .done(function(result){

How can I specify the timeout?

First suspect is here, if you are not getting more than 101 records from db then first check that query.

Sorry for the confusion InsaneSkull. My original post was erred and pointing to the wrong issue as I later clarified.

The issue seems to be with the

Model::loadMultiple($modelsDrivers, Yii::$app->request->post());

not getting all the entries?

I was wondering if it could be some timeout issue? I’m truly lost, not even sure how to troubleshoot as even using VarDumper::dump produces an error which doesn’t occur otherwise.

Would you have any suggestions on how to figure the underlying issue here?

And most importantly, Thank you for your help!

My app is running on Azure/Azure SQL, but I just copied the data to a local instance running on Apache/MySQL and I get

Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini

First am not sure why you want to enter such a big number of Items. Sounds to me like a bad design. If you can, you can split the process into multiple stages instead of just making Big monolithic post.

That being advised, you can easily change PHP ini using text editor. Without knowing your Environment (servers, OS, et al it is hard to be specific). In caase you want to do only for that specific controller then do something like

public function actionUpdate($id)
{
    ini_set("max_input_vars", 3000);
    
    $model = $this->findModel($id);
    $modelsDrivers = $model->drivers;
    // .............
}

See php - How to change max_input_vars - Stack Overflow

This is a contact form for a business which include an employee listing. Originally, it was only supposed to house 5-10 employees per business, but this is an exceptional entry with over a hundred which brought it over the limit.

You are right, a serious look at the design is needed now, but my immediate need is to fix the issue and I think you may have just provided me with a temporary workaround.

Sadly, the

ini_set("max_input_vars", 3000);

has no effect in the Azure environment. I have contacted their IT Admin to request the ini be updated.

Thank you.

Have you thought of Importing Excel/CSV instead? That makes more sense in such cases. Create excel and then import it to the database. and reserve the other one for few records

You need to set the max_input_vars value even higher, e.g 1000000 to be on the safe side.

It was set to 1000 and doubled it to 2000, so the application is working again.

Does increasing this going to impact server resources/performance? Can this be detrimental at all? If not, why not increase it to 1000000 so this never causes an issue?

it will not impact, it just enables you to be handle larger form postings, as your application requires. But if 2000 is working now, just test with larger forms and see at what point the 2000 becomes insufficient.

It will do when you send a lot of data. But you will only notice it when many requests posts simultaneously those data. It all depends on how big traffic to that endpoint is!