php - Yii 1.x - required field saves empty -


i have field set required in model, yet have seen users saving empty string (ie. ''). when tested it, receive "cannot blank" message properly, don't know how prevent in future. have specify scenarios in rule (eg, 'insert', 'update')? way, tried updating field, , doesn't let me save empty (i tries spaces).

these rules applied on field (model):

public function rules() {     return array(         array('field', 'required'),         array('field', 'length', 'max'=>4096),         array('field', 'safe', 'on'=>'search'),     ); } 

for @riggsfolly :) controller action:

public function actionupdate($id) {     $model = model::model()->findbypk($id);      $formdata = yii::app()->request->getpost('model');       if ($formdata)     {          $model->attributes = $formdata;         $model->save();      }      $this->render('update',array(         'model'=>$model      )); } 

... , view:

<?php $form=$this->beginwidget('cactiveform', array(     'id'=>'form' )); ?>  <?php echo $form->textarea($model,'text',array( 'rows'=>5 ')); ?>  <?php $this->endwidget(); ?> 

can imagine scenario field saving empty string in database?


Comments

Popular posts from this blog

php - trouble displaying mysqli database results in correct order -

depending on nth recurrence of job in control M -

sql server - Cannot query correctly (MSSQL - PHP - JSON) -