我想在同一页面中验证2个表单,请建议我最好的方法,也指导我使用表单验证而不使用保存功能(这是jst演示程序)
index.ctp
echo $this->Form->create($temp1);
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->button('Save');
echo $this->Form->end();
echo $this->Form->create($temp2);
echo $this->Form->input('name');
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->button('Save');
echo $this->Form->end();
控制器
public function index(){
$temp1 = $this->Contact->newEntity($this->request->data);
if ($this->request->is('post')) {
$temp1 = $this->Contact->patchEntity($temp1, $this->request->data);
if($this->Contact->save($temp1))
{
}
}
}
答案 0 :(得分:1)
您可以使用plunker轻松验证表单。看看链接。
答案 1 :(得分:0)
要进行验证,请转到Model / Table / PostTable.php
public function validationDefault(Validator $validator){
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->notEmpty('name');
$validator
->allowEmpty('email');
$validator
->allowEmpty('password');
return $validator;
}
答案 2 :(得分:0)
您可以通过jquery验证中具有不同ID的两个表单进行验证