I am new to yii and having trouble with client side validation for my textarea. I am not sure what I am doing wrong but for some reason the client side validation does not work only for this textarea.
Below is my rules in my model:
public function rules()
{
return array(
array('content', 'required'),
array('user_id, seen', 'numerical', 'integerOnly'=>true),
array('datetime', 'safe'),
array('id, user_id, content, datetime, seen', 'safe', 'on'=>'search'),
);
}
Here is the code in my view:
<?php $form=$this->beginWidget('TbActiveForm', array(
'id'=>'post-form',
'action'=>Yii::app()->createUrl('/feedback/default/create'),
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<div class="modal-header">
<a class="close" id="close_modal" onclick="idEmpty(event)">×</a>
<h4>New Feedback</h4>
</div>
<div class="modal-body">
<?php echo $form->textarea($model,'content', array('id'=>'feedback_content','class'=>'feedback_textarea')); ?>
<?php echo $form->error($model,'content'); ?>
</div>
<div class="modal-footer">
<div class="hint" style="float:left">
<span style="color:red;font-weight: bold">Hint: </span>You can use <?php echo CHtml::link('markdown', 'http://daringfireball.net/projects/markdown/syntax'); ?> syntax!
</div>
<?php echo TbHtml::submitButton('Send Feedback', array('color' => TbHtml::BUTTON_COLOR_SUCCESS)); ?>
</div>
<?php
$this->endWidget();
?>
and finally this is my controller:
public function actionCreate()
{
$model=new Feedback;
if(isset($_POST['Feedback'])) {
$model->attributes = $_POST['Feedback'];
$model->user_id = Yii::app()->user->getId();
$model->datetime = date("Y-m-d H:i:s");
$model->seen = 0;
if($model->validate()) {
$model->save();
$this->redirect(array('/dashboard'));
}
else
echo 'cant validate';
}
}
If I try to violate the rule for this textarea, like if I leave it blank, I do not get the proper error message and I end up getting "can't validate" (which is only there for testing purposes). My database is mysql and the intended field is of type "TEXT".
Any help is appreciated. Thanks