简体   繁体   English

Yii Prevent Form提交客户端验证

[英]Yii Prevent Form Submit on client side validation

I'm having an issue trying to make a client side validation on yii 1.1.12. 我在尝试在yii 1.1.12上进行客户端验证时遇到问题。 I have the following 我有以下

<?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'),
)); 
?>

Even using a return false in after validate, my form still being submitted. 即使在验证后使用return false,我的表单仍在提交。 Any way to solve this? 有什么办法解决这个问题?

Thanks. 谢谢。

You may be going right way. 您可能会走对路。 But Yii client side validation also depends on the error you show in form. 但是Yii客户端验证还取决于您在表单中显示的错误。 If your showing error using CHtml::error() method than for that variable client side validation will not happen. 如果使用CHtml::error()方法显示错误,则不会进行该变量客户端验证。 I can't say what you are using as you have not posted any code. 由于您尚未发布任何代码,因此我无法说您正在使用什么。 So try Using $form->error() method. 因此,请尝试使用$form->error()方法。 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/ http://www.waytoblogger.com/blog/technical/yii/yii-client-side-validation/

Try this: 尝试这个:

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

I see in clientOptions you are not doing any specific thing. 我在clientOptions看到您没有做任何特定的事情。 So just removed. 所以就删除了。 And you do not have to include jquery by yourself, As far as i know yii automatically includes it when it is required(Here activeform requires, I guess). 而且您不必自己包括jquery,据我所知yii会在需要时自动包括它(我想这里是activeform要求)。 You may have a look to this url 您可以看一下这个网址

Solved. 解决了。 just removed 刚刚删除

<?php
Yii::app()->clientScript
        ->registerCoreScript('jquery');
?>
'enableClientValidation'=>true,
 'clientOptions' => array('validateOnSubmit'=>true),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM