Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP not showing form validation messages
    primarykey
    data
    text
    <p>I am trying to build my first CakePHP application and I am having some trouble with the form validation not showing when I try to add to the database. On submitting the form I get the flash message (as shown in the controller below), but the individual validation does not show.</p> <p>Model:</p> <pre><code>class Client extends AppModel { public $validate = array ( 'businessName' =&gt; array ( 'mustNotBeBlank'=&gt;array( 'rule'=&gt;'notEmpty', 'message'=&gt;'Must not be empty' ), 'mustBeUnique'=&gt;array( 'rule'=&gt;'isUnique', 'message'=&gt;'Name already registered' ), 'maxLength50'=&gt;array ( 'rule'=&gt;array('maxLength', 50), 'message'=&gt;'Exceeds 50 Characters' ) ), 'address1' =&gt; array ( 'mustNotBeBlank'=&gt;array( 'rule'=&gt;'notEmpty', 'message'=&gt;'Must not be empty' ), 'maxLength50'=&gt;array ( 'rule'=&gt;array('maxLength', 50), 'message'=&gt;'Exceeds 50 Characters' ) ), 'address2' =&gt; array ( 'mustNotBeBlank'=&gt;array( 'rule'=&gt;'notEmpty', 'message'=&gt;'Must not be empty' ), 'maxLength50'=&gt;array ( 'rule'=&gt;array('maxLength', 50), 'message'=&gt;'Exceeds 50 Characters' ) ), 'address3' =&gt; array ( 'mustNotBeBlank'=&gt;array( 'rule'=&gt;'notEmpty', 'message'=&gt;'Must not be empty' ), 'maxLength50'=&gt;array ( 'rule'=&gt;array('maxLength', 50), 'message'=&gt;'Exceeds 50 Characters' ) ), 'postCode' =&gt; array ( 'mustNotBeBlank'=&gt;array( 'rule'=&gt;'notEmpty', 'message'=&gt;'Must not be empty' ), 'postCode' =&gt; array( 'rule'=&gt;array('postal', null, 'uk'), 'message'=&gt;'Please enter a valid postcode' ) ), 'telephone1' =&gt; array ( 'mustNotBeBlank'=&gt;array( 'rule'=&gt;'notEmpty', 'message'=&gt;'Must not be empty' ), 'maxLength11'=&gt;array ( 'rule'=&gt;array('maxLength', 11), 'message'=&gt;'Exceeds phone number length' ), 'mustBeNumber'=&gt;array( 'rule' =&gt;'numeric', 'message' =&gt; 'Must be a number' ) ), 'telephone2' =&gt; array ( 'maxLength11'=&gt;array ( 'rule'=&gt;array('maxLength', 11), 'message'=&gt;'Exceeds phone number length' ), 'mustBeNumber'=&gt;array( 'rule' =&gt; 'numeric', 'message' =&gt; 'Must be a number' ) ), 'email' =&gt; array ( 'rule' =&gt; array('email', true), 'message' =&gt; 'Please supply a valid email address.' ), 'domain' =&gt; array ( 'rule' =&gt; 'url', 'message' =&gt; 'Please supply a valid email address.' ) ); } </code></pre> <p>View (html removed for simplicity):</p> <pre><code>echo $this-&gt;form-&gt;create(); echo $this-&gt;Form-&gt;input('businessName', array('label' =&gt; 'Business Name')); echo $this-&gt;Form-&gt;input('address1', array('label' =&gt; 'Address')); echo $this-&gt;Form-&gt;input('address2', array('label' =&gt; '')); echo $this-&gt;Form-&gt;input('address3', array('label' =&gt; '')); echo $this-&gt;Form-&gt;input('postCode', array('label' =&gt; 'Postcode')); echo $this-&gt;Form-&gt;input('telephone1', array('label' =&gt; 'Landline')); echo $this-&gt;Form-&gt;input('telephone2', array('label' =&gt; 'Mobile')); echo $this-&gt;Form-&gt;input('email', array('label' =&gt; 'Email')); echo $this-&gt;Form-&gt;input('domain', array('label' =&gt; 'Domain')); $options = array( 'label' =&gt; 'Add', 'div' =&gt; array( 'class' =&gt; 'btn btn-primary', ) ); echo $this-&gt;Form-&gt;end($options); </code></pre> <p>Add action in controller:</p> <pre><code>public function add() { if ($this-&gt;request-&gt;is('post')) { $this-&gt;Client-&gt;create(); if ($this-&gt;Client-&gt;save($this-&gt;request-&gt;data)) { $this-&gt;Session-&gt;setFlash('Client has been saved.'); $this-&gt;redirect(array('action' =&gt; 'index')); } else { $this-&gt;Session-&gt;setFlash('Unable to add your post.'); } } } </code></pre> <p>Thanks once again for any help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload