2013-01-01 2 views
0

첫 번째 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.'); 
     } 
    } 
} 

감사합니다.

+0

먼저 데이터베이스 이름을 살펴보십시오. http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html – Jelmer

답변

7

귀하의 양식 작성 태그

echo $this->form->create(); 

하지만

echo $this->Form->create(); 

공지 F. 그냥 로컬 모두 시도 대문자와 소문자이어야한다 -> 형태는 오류 메시지를보고하는 데 실패합니다.

+0

나의 사과, 이것은 코드를 SO로 복사하는 실수였습니다 –

+3

아, 양식 작성 태그가 문제입니다 .. . echo $ this-> form-> create(); 은 이어야합니다. echo $ this-> Form-> create(); 여기에서 모두 시도했지만 소문자로 오류를보고하지 못했습니다. 나는 이것을 반영하기 위해 나의 대답을 업데이트했다. – Happy

+0

도와 주셔서 감사합니다. –