php - Yii2 form field stays blank even when filled -
i have update form works expected 1 exception - review
textarea
doesn't wan't pass through validation rules. when fill , try update form review field empty
(or sort of this). can see var_dump($model->geterrors())
in controller. $_post['author']['review']
got value gave can't save in $model->review
column. using ckeditor
. tried without without success. here controller:
public function actionupdate($id) { $model = $this->findmodel($id, true); $settings = new settings(); if ($model->load(yii::$app->request->post())) { var_dump($model->save()); var_dump($model->geterrors());die; $languages = lang::find()->all(); foreach ($languages $language) { if ($language->default != 1) { $names = 'names_' . $language->url; $varnames = yii::$app->outdata->sanitize($model->$names); $model->$names = $varnames; $review = 'review_' . $language->url; $varreview = yii::$app->outdata->sanitize($model->$review); $model->$review = $varreview; $metadesc = 'meta_desc_' . $language->url; $varmetadesc = yii::$app->outdata->sanitize($model->$metadesc); $model->$metadesc = $varmetadesc; $url = 'url_' . $language->url; $varurl = yii::$app->outdata->sanitize($model->$url); $model->$url = $varurl; $cbirth = 'country_birth_' . $language->url; $varcbirth = yii::$app->outdata->sanitize($model->$cbirth); $model->$cbirth = $varcbirth; } else { $model->names = yii::$app->outdata->sanitize($model->names); $model->review = yii::$app->outdata->sanitize($model->review); $model->meta_desc = yii::$app->outdata->sanitize($model->meta_desc); $model->url= yii::$app->outdata->sanitize($model->url); $model->country_birth = yii::$app->outdata->sanitize($model->country_birth); } } //записване на изображенията + thumb if (isset($_post["author"]["imagefiles"]) , ! empty($_post["author"]["imagefiles"])) { $model->imagefiles = uploadedfile::getinstances($model, 'imagefiles'); if (isset($model->imagefiles) , count($model->imagefiles) > 0) { foreach ($model->imagefiles $key => $file) { $parseprodtitle = makeurl::parseimagename($model->names.'_'.$model->id); $filename = $parseprodtitle . '_' . $model->id . '.' . $file->extension; $filename = yii::$app->translate->cyr_to_lat($filename); $model->filename = $filename; $model->update(); $pic = yii::getalias('@frontend/web') . '/authors/thumb-270/' . $filename; $pic2 = yii::getalias('@frontend/web') . '/authors/' . $filename; $file->saveas(yii::getalias('@frontend/web') . '/authors/' . $filename); $image = file_get_contents(yii::getalias('@frontend/web') . '/authors/' . $filename); file_put_contents($pic, $image); $model->resizeimg($pic); $settings->compress($pic, $pic, 90); $settings->compress($pic2, $pic2, 90); } } } $model->update(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, ]); } }
the part of view review
field:
echo '<div class="row">'; echo '<div class="col-sm-12">'; $textcontent = 'review'; if (!$model->isnewrecord) { $model->$textcontent = outdata::showtxt($model->$textcontent); } echo $form->field($model, 'review')->textarea(); echo "<script> ckeditor.replace( 'author[review]' ); </script>"; echo '</div>'; echo '</div>';
and model rules:
public function rules() { $required = ['names', 'review', 'meta_desc', 'url', 'birthday', 'country_birth']; return [ [$required, 'required'], [['active', 'sort'], 'required'], ['names', 'string', 'max' => 255], ['country_birth', 'string', 'max' => 255], ['review', 'string'], ['homeslider_review', 'string'], ['meta_desc', 'string', 'max' => 170], ['url', 'string', 'max' => 60], [['active', 'sort'], 'integer'], [['filename'], 'string'], ]; }
all other fields work in proper way. rebel. thank in advance!
in code ok.if u don't want validate model, try 1 in controller u r saving form.
var_dump($model->save(false));
this solve problem
Comments
Post a Comment