ログインフォームがあります。notempty()
ルールでフィールドを検証したい。すべてのエラーメッセージを一度に表示したい(フィールドaは空です)。私の場合、これは起こりません。
私のコードは:
if(empty($this->data['Employee']['username'])){
$this->Employee->invalidate('username','Please Enter User Name');
}
else if(empty($this->data['Employee']['password'])){
$this->Employee->invalidate('password','Please Enter Password');
}
else if(empty($this->data['Employee']['project_id'])){
$this->Employee->invalidate('project_id','Please Select Any Project.');
$this->redirect(array('controller'=>'employees','action' => 'login'));
}
Login.ctpファイル:
<?php echo $this->Form->create('Employee', array('action' => 'login'));?>
<h2>Login</h2> <div id="login-area">
<?php echo $this->Form->input('username',array('div'=>false,'id'=>'loginusername'));?>
<?php echo $this->Form->input('password',array('div'=>false,'type'=>'password','id'=>'password'));?>
<?php echo $this->Form->input('project_id',array('id'=>'projects','empty'=>'Select'));?>
<?php echo $this->Form->end(__('submit',true));?>
コントローラ機能:
function login(){
$this->layout = 'login'; //pr($this->data);exit;
if(isset($this->data['Employee'])){
if(empty($this->data['Employee']['username'])){
$this->Employee->invalidate('username','Please Enter User Name');
}
else if(empty($this->data['Employee']['password'])){
$this->Employee->invalidate('password','Please Enter Password');
}
else{
//$project_id = $this->data['Employee']['project_id'];
$result=$this->Employee->findByUsername($this->data['Employee']['username']);
$pwd=$result['Employee']['password'];echo $pwd;
$emp_id =$result['Employee']['id'];
if($pwd==md5($this->data['Employee']['password'])){
//$this->Session->write('project_id',$project_id);
$this->Session->write('emp_id',$emp_id);
$this->redirect(array('action' => 'index'));
}
else{
$this->Session->setFlash(__('Please enter valid username And password to login', true));
}
}
}
フォームの送信中にすべてのエラーメッセージを一緒に表示するにはどうすればよいですか?