当我收到密码验证错误时,我会在页面顶部显示文本错误,因此即使出现验证错误,我也想保留我的文件数据。我正在使用重定向,所以还有另一种方法可以做到这一点?
public function inscriptioncompte(){
if ($this->request->is(array('post', 'put'))) {
$posted_data = $this->request->data;
$this->User->create();
if($this->checkPassword($posted_data['User']['password'])!="1"){
$this->Session->setFlash($this->checkPassword($posted_data['User']['password']),'ko');
$this->User->validationErrors;
$this->redirect( Router::url( $this->referer(), true ) );
}
else {
$this->User->set(array(
'username'=>$posted_data['User']['username'],
'password'=>$posted_data['User']['password'],
'group_id'=>3));
$datenaissance = date("Y-m-d",strtotime($posted_data['User']['datenaissance']));
if($this->User->validates()){
if($this->User->save()){
$this->Customer->create();
$this->Customer->set(array(
'user_id'=>$this->User->getLastInsertId(),
'nom'=>$posted_data['User']['nom'],
'prenom'=>$posted_data['User']['prenom'],
'adresse'=>"Pas encore d\'adresse ",
'email'=>$posted_data['User']['username'],
'datenaissance'=> $datenaissance,
'ville'=>$posted_data['User']['ville'],
'telephone1'=>$posted_data['User']['telephone1'],
'telephone2'=>"",
'interet'=>""
)
);
if($this->Customer->save()){
$this->Session->setFlash("Verifier votre boite mail afin de valider votre inscription.",'ok');
$this->redirect( Router::url( $this->referer(), true ) );
}else{
$this->Session->setFlash("Une erreur c'est produite lors de votre inscription.",'ko');
$this->redirect( Router::url( $this->referer(), true ) );
}
}else{
$this->Session->setFlash("Une erreur c'est produite lors de votre inscription.",'ko');
$this->redirect( Router::url( $this->referer(), true ) );
}
}else{
$erreurs = $this->User->invalidFields();
$erreurToShow = "";
if(isset($erreurs['username']['0']) && !empty($erreurs['username']['0'])){
$erreurToShow = $erreurs['username']['0'];
}
if(isset($erreurs['password']['0']) && !empty($erreurs['password']['0'])){
$erreurToShow = $erreurToShow.$erreurs['password']['0'];
}
$this->Session->setFlash("Erreur : ".$erreurToShow,'ko');
$this->redirect( Router::url( $this->referer(), true ) );
}
}
}
}