# Display Form Validation Errors CakePHP 3

**URL:** <https://discourse.cakephp.org/t/display-form-validation-errors-cakephp-3/1005>\
**Category:** Need Help\
**Created:** [August 19, 2016, 7:40am UTC](https://discourse.cakephp.org/t/display-form-validation-errors-cakephp-3/1005 "2016-08-19T07:40:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhoopathi\_smash](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bhoopathi\_smash](https://discourse.cakephp.org/u/bhoopathi_smash)\
**Post date:** [August 19, 2016, 7:40am UTC](https://discourse.cakephp.org/t/display-form-validation-errors-cakephp-3/1005/1 "2016-08-19T07:40:59Z")

</div>

Hi ,  
In my user register form I am using cakephp model validation. The validation  
is working perfectly. Unfortunately the validation error messages are  
not displaying on my form. Would you please help me on this?

The code I am using is as follows. Please advise me what I am missing here.

## Model:
\<?php namespace App\Model\Table; use Cake\ORM\Table; use Cake\Validation\Validator; class UsersTable extends Table { public function initialize(array $config) { $this-\>table('tp\_users'); $this-\>primaryKey('user\_id'); } public function validationDefault(Validator $validator) { $validator = new Validator(); $validator -\>notEmpty('username', 'A username is required') -\>add('username', 'unique', ['rule' =\> 'validateUnique', 'provider' =\> 'table', 'message' =\> 'Not unique']) -\>notEmpty('email', 'A email is required') -\>add('email', 'validFormat', ['rule' =\> 'email', 'message' =\> 'E-mail must be valid']) -\>add('email', 'unique', ['rule' =\> 'validateUnique', 'provider' =\> 'table', 'message' =\> 'Not unique']) -\>notEmpty('password', 'A password is required') -\>lengthBetween('password', [6, 8]) -\>add('profile\_image', 'file', ['rule' =\> ['mimeType', ['image/jpeg', 'image/jpg', 'image/png']], 'message' =\> 'Only jpeg, jpg, and png image extension are allowed to upload..', ]); /\* $errors = $validator-\>errors($this-\>request-\>data()); if (!empty($errors)) { // Send an email. } \*/ return $validator; } } Controller: -------------------------------------------- public function add($role = null) { $this-\>viewBuilder()-\>layout('customer\_register'); // New in 3.1 $this-\>set(compact('role')); $user = $this-\>Users-\>newEntity($this-\>request-\>data); if ($this-\>request-\>is('post')) { //echo print\_r($this-\>request-\>data); //die; if ($this-\>request-\>data['password'] == $this-\>request-\>data['conpassword']) { /\* echo $this-\>request-\>data['password']; echo $this-\>request-\>data['conpassword']; die; \*/ //$user = $this-\>Users-\>patchEntity($user, $this-\>request-\>data); if ($this-\>Users-\>save($user)) { $this-\>Flash-\>success(\_\_('The user has been saved.')); return $this-\>redirect(['action' =\> 'index']); } else { $this-\>Flash-\>error(\_\_('Unable to add the user.')); return $this-\>redirect(['action' =\> 'add', $role]); } } else { /\* echo $this-\>request-\>data['password']; echo $this-\>request-\>data['conpassword']; die; \*/ $this-\>Flash-\>error(\_\_('Password and Confirm Password Mis Match')); return $this-\>redirect(['action' =\> 'add', $role]); } } $this-\>set('user', $user); } View: ---------------------------------------------

 ![logo](https://yyz1.discourse-cdn.com/flex029/img/logo.png "logo")
* * *

 \<?php //echo $this-\>Flash-\>render(); ?\>

```
    <?php echo $this->Flash->render('auth'); ?>
    <?= $this->Form->create($user) ?>
        <label>Username</label>
        <div class="input-group">
            <?= $this->Form->input('username',array('type'=>'text','class'=>'form-control','placeholder'=>'Username','label'=>false,'required'=>true)) ?>                
            
        </div>
        <label>Email</label>
        <div class="input-group">
            <?= $this->Form->input('email',array('type'=>'email','class'=>'form-control','placeholder'=>'Email','label'=>false,'required'=>true)) ?>
        </div>
        <label>Password</label>
        <div class="input-group">
            <?= $this->Form->input('password',array('class'=>'form-control','placeholder'=>'Password','type'=>'password','label'=>false,'required'=>true)) ?>
        </div>
        <label>Confirm Password</label>
        <div class="input-group">
            <?= $this->Form->input('conpassword',array('class'=>'form-control','placeholder'=>'Confirm Password','type'=>'password','label'=>false,'required'=>true)) ?>
        </div>
        <?= $this->Form->input('role_id',array('type'=>'hidden','label'=>false,'value'=>$role)) ?>
        <?php //echo $this->Form->button(__('Submit')); 
        ?>
        <?php echo $this->Form->button('Submit', array('formnovalidate' => true)); 
        ?>
    <?= $this->Form->end(); ?>

</div>

```
