Note that there are some explanatory texts on larger screens.

plurals
  1. POyii how to show the custom error msg with validation failed msg
    text
    copied!<p>I would like to show my custom error msg with rule validation fail error msg. How can I do it?</p> <p>this set msg from controller</p> <pre><code>$expire_date_error = '&lt;p&gt;Please enter the company license expire date more than notification days&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Expire Date is less than notificaion days on current date.&lt;/li&gt; &lt;/ul&gt;'; Yii::app()-&gt;user-&gt;setFlash('expire_date_error',$expire_date_error); $this-&gt;render('create',array( 'model'=&gt;$model, </code></pre> <p>this get msg from view.</p> <pre><code>&lt;?php if(Yii::app()-&gt;user-&gt;hasFlash('expire_date_error')):?&gt; &lt;div class="errorMessage"&gt; &lt;?php echo Yii::app()-&gt;user-&gt;getFlash('expire_date_error'); ?&gt; &lt;/div&gt; &lt;?php endif; ?&gt; </code></pre> <p>I used some code from <a href="http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/" rel="nofollow">http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/</a></p> <p>regards =======================+++++++++++++++++++++++++++++++++==========================</p> <p>Update question.</p> <p>This is my controller</p> <pre><code>public function actionCreate() { $model=new CompanyLicense; // Uncomment the following line if AJAX validation is needed // $this-&gt;performAjaxValidation($model); if(isset($_POST['CompanyLicense'])) { $currentTime = date('Y-m-d h:i:s', time()); $model-&gt;attributes= $_POST['CompanyLicense']; $model-&gt;created = $currentTime; $model-&gt;active = 1; $model-&gt;expire_date= $_POST['CompanyLicense']['expire_date']; if($model-&gt;checkExpireDate()) { $model-&gt;file_name=CUploadedFile::getInstance($model,'file_name'); $folder = Yii::getPathOfAlias('webroot').'/images/'; if($model-&gt;save()) { mkdir($folder.$model-&gt;id); $model-&gt;file_name-&gt;saveAs($folder. $model-&gt;id . "/" . $model-&gt;file_name); $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id)); } }else{ //echo 'debug'; $expire_date_error = '&lt;p&gt;Please enter the company license expire date more than notification days&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Expire Date is less than notificaion days on current date.&lt;/li&gt; &lt;/ul&gt;'; Yii::app()-&gt;user-&gt;setFlash('expire_date_error',$expire_date_error); } } $this-&gt;render('create',array( 'model'=&gt;$model, )); } public function checkExpireDate($attribute='',$params ='') { $currentTime = date('Y-m-d', time()); $currentTime = date('Y-m-d', strtotime($currentTime . '+ ' . $this-&gt;notification_days.' days')); if ($currentTime &gt; $this-&gt;expire_date) return false; return true; //$this-&gt;addError($this-&gt;expire_date,'should be more ' . $this-&gt;notification_days . ' days on current date!'); } </code></pre> <p>I want to show this error with other validation failed error msg.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload