Gibt es eine Möglichkeit nur zu bekommen, ist warning
in yii
wieWarnung in yii Form Vorlage
Ich habe ein form
<?php
/* @var $this UserController */
/* @var $model User */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true,
'enableClientValidation' => true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'mobile'); ?>
<?php echo $form->textField($model,'mobile',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'mobile'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Ich weiß, wenn ich unique
Handy-Nummer will, dann muß ich einzigartig definieren rule
dafür in Model
, aber ich will, dass, wenn eine Handynummer eingegeben wird, die bereits existiert, dann bekomme ich nur eine warning
Nachricht, aber form
Übermittlung ist erlaubt.
So habe ich versucht, diese
User.php
public function rules()
{
return array(
array('mobile', 'checkDublicateExist', 'on'=>'createuser'),
);
}
public function checkDublicateExist($attribute,$params)
{
if(!empty($this->mobile)){
$count = User::Model()->count("mobile=:mobile", array("mobile" => $this->mobile));
if($count){
$this->addError('mobile' 'This mobile already exist!');
return true;
}
}
}
ich für true zurück, indem Sie dieses validation
passieren, aber das wird mir erlaubt, nicht Formular abzuschicken. Ich will nur Warnung für Benutzer