1
我在我所使用ckeditor
警予文本字段validtaion
<div class="row">
<?php echo $form->labelEx($model,'text'); ?>
<?php echo $form->textArea($model, 'text', array('id'=>'editor1')); ?>
<?php echo $form->error($model,'text'); ?>
</div>
<script type="text/javascript">
CKEDITOR.replace('editor1');
</script>
規則在模型中的text field
是
public function rules()
{
return array(
array('text', 'required'),
array('text', 'validateWordLength')
);
}
public function validateWordLength($attribute,$params)
{
$total_words= str_word_count($this->text);
if($total_words>4000)
{
$this->addError('text', 'Your description length is exceeded');
}
if($total_words<5)
{
$this->addError('text', 'Your description length is too small');
}
}
這工作得很好
1)當我離開現場blnk我得到所需的文本錯誤。
2)當我寫的話他們少5個或多於4000我得到想要的錯誤
,但是當我插入一些空白空間,然後我沒有得到任何錯誤,並提交表單。
請幫助任何幫助將不勝感激!
嘗試用$ total_words = str_word_count(修剪($這個 - >文本)); –