Hi there,
Im new to this forum but i really like it, I have already found alot of answers here.
Anyway, I must say that I just started working with the yii framework.
I’m working on this project and the problem is when I register with an email address which is already in the database, there is no error coming onto the screen, but just a blank page…
This is my registerForm.
<?php
/**
-
LoginForm class.
-
LoginForm is the data structure for keeping
-
user login form data. It is used by the ‘login’ action of ‘SiteController’.
*/
class RegistreerForm extends CFormModel
{
public $firstname;
public $lastname;
public $email;
public $riziv;
public $code_van_de_orde;
public $phone_number;
private $_identity;
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
array('firstname, lastname,email,riziv, code_van_de_orde', 'required', 'message'=>'Dit veld is verplicht!'),
array('email','unique'),
array('email','email','message'=>'Ongeldig email adres!'),
array('email', 'length', 'max'=>45),
array('firstname, lastname', 'length', 'max'=>25),
array('phone_number', 'match', 'pattern'=>'/^([0-9]{2,3}[/]{0,1}[0-9]{2,3}[-. ]{0,1}[0-9]{2}[-. ]{0,1}[0-9]{2})$/'
,'message'=>'Ongeldig telefoonnr!'),
array('email, firstname, lastname, riziv, code_van_de_orde', 'safe', 'on' => 'search'),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
}
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->email,$this->code_van_de_orde);
if(!$this->_identity->authenticate())
$this->addError('code_van_de_orde','Fout, sommige velden zijn niet correct ingevuld.');
}
}
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function registreer()
{
echo 'functie registreer';
return true;
}
}
This is the method in my controller.
public function actionRegistreer()
{
$model=new RegistreerForm;
$newUser = new User;
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='registreer-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['RegistreerForm']))
{
$model->attributes=$_POST['RegistreerForm'];
$newUser->firstname = $model->firstname;
$newUser->lastname = $model->lastname;
$newUser->email = $model->email;
$newUser->riziv = $model->riziv;
$newUser->code_van_de_orde = $model->code_van_de_orde;
$newUser->phone_number = $model->phone_number;
if($newUser->save()) {
$identity=new UserIdentity($newUser->email,$model->code_van_de_orde);
$identity->authenticate();
Yii::app()->user->login($identity,0);
$categories = Category::model()->findAll();
$labResults = LabResult::model()->findAll();
$this->render('index',array('categories'=>$categories, 'labResults'=>$labResults));
}
}
else
$this->render('registreer',array('model'=>$model));
}
And the view.
<?php
/* @var $this SiteController */
/* @var $model LoginForm */
/* @var $form CActiveForm */
$this->layout=‘main2’;
$this->pageTitle=Yii::app()->name . ’ - Registreer’;
$this->breadcrumbs=array(
'Registreer',
);
?>
<h1>Registreer</h1>
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
'id'=>'registreer-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<p class="note">Velden met een <span class="required">*</span> zijn verplicht.</p>
<div class="row">
<?php echo $form->labelEx($model,'firstname'); ?>
<?php echo $form->textField($model,'firstname'); ?>
<?php echo $form->error($model,'firstname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lastname'); ?>
<?php echo $form->textField($model,'lastname'); ?>
<?php echo $form->error($model,'lastname'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'phone_number'); ?>
<?php echo $form->textField($model,'phone_number'); ?>
<?php echo $form->error($model,'phone_number'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'riziv'); ?>
<?php echo $form->textField($model,'riziv'); ?>
<?php echo $form->error($model,'riziv'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'code_van_de_orde'); ?>
<?php echo $form->textField($model,'code_van_de_orde'); ?>
<?php echo $form->error($model,'code_van_de_orde'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton('Registreer'); ?>
</div>
<?php echo $form->errorSummary($model); ?>
<?php $this->endWidget(); ?>
</div><!-- form -->