1
フォームを保存できないレンダリングビューの編集ビューでユーザー名が検証されるという奇妙な問題が発生しました。私はこのビューにユーザ名の入力がないので、なぜこれが検証されているのですか?フォームにフィールドが存在しなくてもユーザー名が検証されています
次のように検証は次のとおりです。
var $validate = array(
'username' => array(
'empty' => array(
'rule' => 'notEmpty',
'required' => true,
'allowEmpty' => false,
'message' => 'Username is required',
),
'isUnique' => array(
'rule' => 'isUnique',
'message' => 'This username has already been taken'
),
'pattern' => array(
'rule' => array('custom','/[a-zA-Z0-9\_\-]{6,}$/i'),
'message' => 'Must be 6 characters or longer with no spaces',
),
'length' => array(
'rule' => array('maxLength', 15),
'message' => 'Please keep username under 15 characters',
),
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Username cannot be empty',
)
);
以下の編集機能:
function edit($id = null) {
$this->set('title_for_layout', 'Edit Profile');
unset($this->User->validate['email']['email']);
unset($this->User->validate['username']);
if($this->Auth->user('id')==$id) {
$this->set('user', $this->User->read(null, $id));
} else {
$this->Session->setFlash(__('You are not authorised to edit other member profiles', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash(__('Your profile has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Your profile could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->User->read(null, $id);
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
私は、私だけは、フォームを保存することができますが、これは正しい方法ですることはできません解除username
を持っていますこれを行うために。誰かがこれにいくつかの光を当てることができますか?
多くの感謝!
頭に釘を打つ - 私はちょうど来て、何かを書きたいとあなたは私の発見を確認した! '' on '=>' create''は全て欠けていた..ありがとう! – Plastika
required => trueを使用しないことを強くお勧めします。要求は異なって達成することができます – mark
詳細については、 "必要とされる"と "allowEmpty"についての神話を参照してください。http://www.dereuromark.de/2010/09/21/saving-model-data-and-security/ – mark