비슷한 질문이 많지만 그 중 누구도 실제로 나를 도와줍니다. HTML5 양식 유효성 검사 메시지를 트리거 것 같다 나는 데이터베이스에 컴퓨터를 추가하는 형태가CakePHP - 모델 유효성 검사가 작동하지 않습니다.
"모델을 입력하십시오"해야한다 모델 검증 메시지의 대신 "이 필드에 입력하십시오." 여기
내 형태 : 여기echo $this->Form->create('Computer');
echo $this->Form->input('Computer.model', array('label' => 'Model'));
echo $this->Form->input('Computer.memory', array('label' => 'memory'));
echo $this->Form->input('Computer.hdd', array('label' => 'hdd'));
echo $this->Form->input('Computer.price', array('label' => 'price'));
echo $this->Form->end('Save Computer');
인덱스와 전체 컨트롤러 코드이며, 여기에 모델
<?php
class Computer extends AppModel {
public $validate = array(
'model' => array(
'Please enter model name'=> array(
'rule'=>'notEmpty',
'message'=>'Please enter model'
)
)
);
}
?>
나는 다른 형태에서 읽기의 행동
<?php
class ComputersController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function index() {
$this->set('computers', $this->Computer->find('all'));
}
public function add() {
if ($this->request->is('post')) {
if (!empty($this->request->data)) {
$this->Computer->save($this->request->data);
$this->Session->setFlash(__('Your Computer has been saved, or so it seems.....'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('Not sure why we got here 1.'));
} else {
$this->Session->setFlash(__('By right, this should be the index page'));
}
}
}
?>
를 추가 모델 저장 기능을 실행하면 모델 유효성 검사가 자동으로 트리거됩니다. 모델 검증이 작동하도록하려면 어떻게해야합니까?
감사 케빈
거짓
참고로 이동 : <입력 이름 = "데이터 [컴퓨터] [모델]"최대 길이 = "10"유형 = "텍스트"ID = "ComputerModel 같은 모델 필드가 기본값 "required ="required "> 모델 확인 규칙 'notEmpty'가 있기 때문에"필수 "로 표시되는 문제가 발견되었습니다. 이것은 위대합니다. 그러나 여전히 모델 유효성 검사 메시지를 표시하지는 않지만 대신 HTML5 메시지를 표시합니다. – aDvo
Cake는 브라우저에서 처리하는'required = "required"'만 추가합니다. 요소를 검사하고 '필수'속성을 수동으로 제거하면 서버에 도달하게되고 모델에서 메시지를 받게됩니다. Cake는 브라우저 확인 메시지를 변경하지 않습니다. 이것은 수동으로 변경할 수 있습니다 (http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message) – cornelb
이와 비슷한 http://stackoverflow.com/a/21094082/ 2776508 – arilia