In view,
<?php
$form2=$this->beginWidget('CActiveForm', array(
'id'=>'forgot-form',
'action'=>'/Index.php/site/forgot',
'enableClientValidation'=>true,
'clientOptions'=>array('validateOnSubmit'=>true),
)); ?>
<div class="frmFields" style="margin: 0 0 0 40px;">
<?php echo $form2->labelEx($model,'forgotpassword', array("style"=>"color:#C29A4B; font-weight:bold")); ?>
<?php echo $form2->emailField($model,'forgotpassword', array("style"=>"border:1px solid #DCDCDD")); ?>
<?php echo $form2->error($model,'forgotpassword'); ?>
</div>
In Controller,
public function actionForgot($pswdsent='no')
{
$model=new LoginForm('sendpaswd');
if($pswdsent = 'no'){
if(isset($_POST['LoginForm']))
{
$model->attributes=$_POST['LoginForm'];
if($model->validate())
{ die("123");
.............
...............
In LoginForm model,
array('forgotpassword', 'checkemail', 'on'=>'sendpaswd'),
public function checkemail($attribute,$params)
{
$command = Yii::app()->db->createCommand();
$result = $command->select('userregistration.*')
->from('userregistration')
->where('email = "'.$this->forgotpassword.'"')
->queryAll();
if(count($result)==0)
$this->addError('forgotpassword','Email is not registered. Enter correct email address');
else
return true;
}
If I enter an unregistered email and submit the form I get the correct error message. But if I enter a registered email the model doesn’t validate and I don’t get the die output 123