1

我在尝试在 yii 1.1.12 上进行客户端验证时遇到问题。我有以下

<?php
Yii::app()->clientScript
        ->registerCoreScript('jquery');
?>
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'my-form',
    'enableClientValidation' => true,
        'clientOptions'=> array('validateOnSubmit'=>true,
                                 'afterValidate'=>'js:function() 
                                        {     
                                           return false
                                        }'
                                ),
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); 
?>

即使在验证后使用 return false,我的表单仍在提交中。有什么办法可以解决这个问题?

谢谢。

4

4 回答 4

4

You may be going right way. But Yii client side validation also depends on the error you show in form. If your showing error using CHtml::error() method than for that variable client side validation will not happen. I can't say what you are using as you have not posted any code. So try Using $form->error() method. Let me know if still your are facing problem.

Also check the link below given.

<?php
Yii::app()->clientScript
        ->registerCoreScript('jquery');
?>
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'my-form',
    'enableClientValidation' => true,
    'clientOptions'=> array('validateOnSubmit'=>true),
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); 
?>

http://www.waytoblogger.com/blog/technical/yii/yii-client-side-validation/

于 2012-09-28T05:15:16.557 回答
2

试试这个:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'my-form',
    'enableClientValidation' => true,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); 
?>

我看到clientOptions你没有做任何具体的事情。所以就删了。而且您不必自己包含jquery,据我所知,yii会在需要时自动包含它(我猜这里需要activeform)。你可以看看这个网址

于 2012-09-27T16:04:49.963 回答
0

解决了。刚刚删除

<?php
Yii::app()->clientScript
        ->registerCoreScript('jquery');
?>
于 2012-09-27T16:16:43.400 回答
0
'enableClientValidation'=>true,
 'clientOptions' => array('validateOnSubmit'=>true),
于 2014-12-10T10:06:08.603 回答