Hi, I am fairly new to yii, I am sorry if this is a dump question.
I have a “user registration” active record model with bunch of variable mirroring the db column and one variable ($forget_email) that is just on its own, that variable that’s on its own is use if someone forgets their password, the variable will store the email on POST and is then is use to send emails. The problem comes when I submit the post, I have rules so that it will check it must be an email, and require on submit, however only the email checking rule is fired. For the life of me, I could not work out what I have done wrong. Maybe this is obvious to some of you.
Here are the code for the Model:
class Registration extends CActiveRecord
{
public $password_repeat;
public $forget_email;
....
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('email, firstname, lastname, password, company, password_repeat', 'required', 'on'=>'index'),
array('forget_email', 'required', 'on'=>'forgetpassword'),
array('forget_email', 'length', 'min'=>2),
array('confirm', 'numerical', 'integerOnly'=>true),
array('email, forget_email', 'email'),
array('firstname, lastname, password, email, forget_email, company, registrationkey', 'length', 'max'=>255),
array('create_time, password_repeat', 'safe'),
array('password', 'compare'),
array('id, username, password, email, create_time, company, registrationkey', 'safe', 'on'=>'search'),
);
}
On the Controller
class RegistrationController extends Controller
{
public function actionForgetpassword()
{
$model = new Registration;
$message = '';
if(isset($_POST['Registration']))
{
$model->attributes=$_POST['Registration'];
if($model->validate())
{
$message = '
Great email sent.
';
}
}
$this->render('forgetpassword', array('model'=>$model, 'message'=>$message));
}
....
}
The view for the page
<?php /** @var BootActiveForm $form */
$form = $this->beginWidget('bootstrap.widgets.BootActiveForm', array(
'id'=>'passwordrecovery',
'type'=>'horizontal',
'enableAjaxValidation'=>true,
)); ?>
<h1>Forgotten your password?</h1>
<p> </p>
<p class="lead">To reset your password, please enter the registred email address. A link will be emailed to your address which will let you reset your password. </p>
<?php echo $message."<p>"; ?>
Enter your email address:<p></p>
<?php echo $form->textFieldRow($model, 'forget_email', array('class'=>'input-xlarge marginright', 'maxlength'=>100)); ?>
<p></p>
<?php echo CHtml::htmlButton('Send reset request', array('class'=>'btn btn-info', 'type'=>'submit')); echo " or "?>
<?php echo CHtml::link('Cancel', array('site/login'),array('class'=>'btn btn-warning')); ?>
<?php $this->endWidget(); ?>
I am sorry this is a bit long, I have try
echo CActiveForm::validate($model);
and all I see is the email rule firing.
Thanks in advance.
Best Regards
Jason