첫 번째 CakePHP 응용 프로그램을 빌드하려고하는데 데이터베이스에 추가하려고 할 때 폼 유효성 검사에 문제가 있습니다. 양식을 제출할 때 플래시 메시지가 표시되지만 (아래 컨트롤러 참조) 개별 확인은 표시되지 않습니다.CakePHP가 폼 유효성 검사 메시지를 표시하지 않습니다.
모델 :
class Client extends AppModel {
public $validate = array (
'businessName' => array (
'mustNotBeBlank'=>array(
'rule'=>'notEmpty',
'message'=>'Must not be empty'
),
'mustBeUnique'=>array(
'rule'=>'isUnique',
'message'=>'Name already registered'
),
'maxLength50'=>array (
'rule'=>array('maxLength', 50),
'message'=>'Exceeds 50 Characters'
)
),
'address1' => array (
'mustNotBeBlank'=>array(
'rule'=>'notEmpty',
'message'=>'Must not be empty'
),
'maxLength50'=>array (
'rule'=>array('maxLength', 50),
'message'=>'Exceeds 50 Characters'
)
),
'address2' => array (
'mustNotBeBlank'=>array(
'rule'=>'notEmpty',
'message'=>'Must not be empty'
),
'maxLength50'=>array (
'rule'=>array('maxLength', 50),
'message'=>'Exceeds 50 Characters'
)
),
'address3' => array (
'mustNotBeBlank'=>array(
'rule'=>'notEmpty',
'message'=>'Must not be empty'
),
'maxLength50'=>array (
'rule'=>array('maxLength', 50),
'message'=>'Exceeds 50 Characters'
)
),
'postCode' => array (
'mustNotBeBlank'=>array(
'rule'=>'notEmpty',
'message'=>'Must not be empty'
),
'postCode' => array(
'rule'=>array('postal', null, 'uk'),
'message'=>'Please enter a valid postcode'
)
),
'telephone1' => array (
'mustNotBeBlank'=>array(
'rule'=>'notEmpty',
'message'=>'Must not be empty'
),
'maxLength11'=>array (
'rule'=>array('maxLength', 11),
'message'=>'Exceeds phone number length'
),
'mustBeNumber'=>array(
'rule' =>'numeric',
'message' => 'Must be a number'
)
),
'telephone2' => array (
'maxLength11'=>array (
'rule'=>array('maxLength', 11),
'message'=>'Exceeds phone number length'
),
'mustBeNumber'=>array(
'rule' => 'numeric',
'message' => 'Must be a number'
)
),
'email' => array (
'rule' => array('email', true),
'message' => 'Please supply a valid email address.'
),
'domain' => array (
'rule' => 'url',
'message' => 'Please supply a valid email address.'
)
);
}
보기 (단순 제거 HTML) :
echo $this->form->create();
echo $this->Form->input('businessName', array('label' => 'Business Name'));
echo $this->Form->input('address1', array('label' => 'Address'));
echo $this->Form->input('address2', array('label' => ''));
echo $this->Form->input('address3', array('label' => ''));
echo $this->Form->input('postCode', array('label' => 'Postcode'));
echo $this->Form->input('telephone1', array('label' => 'Landline'));
echo $this->Form->input('telephone2', array('label' => 'Mobile'));
echo $this->Form->input('email', array('label' => 'Email'));
echo $this->Form->input('domain', array('label' => 'Domain'));
$options = array(
'label' => 'Add',
'div' => array(
'class' => 'btn btn-primary',
)
);
echo $this->Form->end($options);
컨트롤러에 액션을 추가 : 어떤 도움 주셔서 다시 한 번
public function add() {
if ($this->request->is('post')) {
$this->Client->create();
if ($this->Client->save($this->request->data)) {
$this->Session->setFlash('Client has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your post.');
}
}
}
감사합니다.
먼저 데이터베이스 이름을 살펴보십시오. http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html – Jelmer