Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP submit form with validation problem
    primarykey
    data
    text
    <pre><code> echo $this-&gt;Form-&gt;create('Comment', array('url'=&gt;array('controller' =&gt; 'comments', 'action' =&gt;'add', $listposts['Post']['id']) ) ); echo $this-&gt;Form-&gt;input('post_id',array('type'=&gt;'hidden','style'=&gt;'width:30%','value'=&gt;$listposts['Post']['id'])); echo $this-&gt;Form-&gt;input('name',array('style'=&gt;'width:30%')); echo $this-&gt;Form-&gt;input('email',array('style'=&gt;'width:30%')); echo $this-&gt;Form-&gt;input('body',array('rows'=&gt;'5')); echo $this-&gt;Form-&gt;end('Submit'); </code></pre> <p>If any of that three fields is empty it's still saving data into table. How can i stop saving data if one input field is empty. But the column of comments table is not null.</p> <pre><code>mysql&gt; describe comments; +----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | post_id | int(11) | NO | MUL | NULL | | | name | varchar(255) | NO | | NULL | | | email | varchar(255) | NO | | NULL | | | body | varchar(500) | NO | | NULL | | | created | datetime | YES | | NULL | | | modified | datetime | YES | | NULL | | +----------+--------------+------+-----+---------+----------------+ 7 rows in set (0.00 sec) </code></pre> <p>Comment model =></p> <pre><code>&lt;?php class Comment extends AppModel { var $useTable='comments'; var $belongsTo = array('Post'); } </code></pre> <p>Model with validation but it's not displaying any message , but it doesn't save data.</p> <pre><code>post&lt;?php class Comment extends AppModel { var $useTable='comments'; var $belongsTo = array('Post'); var $validate = array( 'name' =&gt; array( 'required' =&gt; true, 'rule' =&gt; 'notEmpty', 'allowEmpty' =&gt; false, 'message' =&gt; 'Enter Name.' ), 'email' =&gt; array( 'required' =&gt; true, 'rule' =&gt; 'notEmpty', 'allowEmpty' =&gt; false, 'message' =&gt; 'Enter Email.' ), 'body' =&gt; array( 'required' =&gt; true, 'rule' =&gt; 'notEmpty', 'allowEmpty' =&gt; false, 'message' =&gt; 'Enter Body.' ) ); } </code></pre>
    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.
 

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