php - Getting forms made with ActiveForm in Yii2 to populate POST data on errors when fields have initial values -


i have set many forms using activeform yii2 , populate fields correct $_post data on errors, having problems doing forms filled data, such users want update existing values - on submit if error fields contain initial value , not $_post value.

here example of form:

$form = activeform::begin();  <?=$form->field($model, 'site_url', ['inputoptions' => ['value' => yii::$app->params['settings']['site_url']]]); ?>  activeform::end(); 

i hoping yii automatically override initial value since post , use value of model $site_url property, unfortunately not case.

is there easy way handle this? ... possible way thought of avoid setting value via fields , instead set model property values initial values , yii should automatically load values in , on post have $_post values.

...unless there easier/better way?

one option checking if has loaded value, , if not set value in params:

$form->field($model, 'site_url',      ['inputoptions' =>        ['value' => (!empty($model->site_url) ?          $model->site_url : yii::$app->params['settings']['site_url']]]); 

Comments