次のように、ログイン用と登録用の2つのフォームを持つ1つのビューがあります:signup.ctp //myビュー
<div>
<?php
echo $this->Form->create("Tbluser");
echo $this->Form->hidden('formsent', array('value' => 'signup'));
echo $this->Form->input('username' ,array('label'=>'Username'));
echo $this->Form->input('password' ,array('label'=>'Password','type' => 'password'));
echo $this->Form->input('email' ,array('label'=>'Email'));
echo $this->Form->end('Register');
?>
</div>
<div>
<?php
echo $this->Form->create("Tbluser"); ?>
echo $this->Form->hidden('formsent', array('value' => 'login'));
echo $this->Form->input('username' ,array('label'=>"Username :"));
echo $this->Form->input('password' ,array('label'=>"Password :",'type' => 'password'));
echo $this->Form->end('Login');
?>
<div>
私が両方のフォームに使用しているモデルは次のとおりです。
<?php
class Tbluser extends AppModel{
public $validate = array(
'username'=>array(
array(
'rule'=>'alphaNumeric',
'allowEmpty'=>false,
'message'=>'Invalide Username!'
),
array(
'rule' => array('minLength', '4'),
'message' => 'Username has to be more than 3 chars'
),
array(
'rule'=>'isUnique',
'message'=>'Username already taken!'
)
),
'password' => array(
array(
'rule' => 'alphaNumeric',
'allowEmpty'=>false,
'message' => 'Password must be AlphaNumeric!'
),
array(
'rule' => array('minLength', '4'),
'message' => 'Username has to be more that 3 chars'
)
),
'email'=>array(
array(
'rule'=>array('email',true),
'required'=>true,
'allowEmpty'=>false,
'message'=>'Invalide email adress!'
),
array(
'rule'=>'isUnique',
'message'=>'Mail adress already taken!'
)
)
);
}
?>
私が使用しているコントローラーは次のとおりです。
<?php
class TblusersController extends AppController
{
public $uses = array(
'Tbluser'
);
public function signup()
{
if ($this->request->is('post')) {
if ('signup' === $this->request->data['Tbluser']['formsent']) {
// Registration part.
}else if('login' === $this->request->data['Tbluser']['formsent']){
//Login part
}
}
}
?>
私のAppControllerは次のようになります:
<?php
class AppController extends Controller {
public $helpers = array('Form', 'Html');
public $components = array('Session','Cookie','Auth'=>array(
'authenticate'=>array(
'Form' => array(
'userModel' => 'Tblforumuser',
'fields' => array(
'username' => 'username',
'password' => 'password'
)
)
)
));
}
?>
現在、サインアップ フォームに間違ったデータを入力して送信すると、検証が行われますが、ログイン フォーム フィールドでも検証が行われるため、両方のフォームではなく、そのサインアップ フォームにのみ適用されるように検証を設定するにはどうすればよいですか? ありがとう。