# Set Validation on form:Cakephp 3

**URL:** <https://discourse.cakephp.org/t/set-validation-on-form-cakephp-3/2707>\
**Category:** Need Help\
**Created:** [June 14, 2017, 8:03am UTC](https://discourse.cakephp.org/t/set-validation-on-form-cakephp-3/2707 "2017-06-14T08:03:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepakverma](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@deepakverma](https://discourse.cakephp.org/u/deepakverma)\
**Post date:** [June 14, 2017, 8:03am UTC](https://discourse.cakephp.org/t/set-validation-on-form-cakephp-3/2707/1 "2017-06-14T08:03:55Z")

</div>

LoginControlller.php

namespace App\Controller;  
use Cake\ORM\TableRegistry;

use App\Controller\AppController;  
class LoginController extends AppController  
{  
public function initialize()  
{  
parent::initialize();

```
    $this->loadComponent('Flash'); // Include the FlashComponent
}

public function index()
{
	$this->set('login', $this->Login->find('all'));
    $this->set(compact('login'));	
}

public function add()
{
    $login = $this->Login->newEntity();
    if ($this->request->is('post')) {
        $login = $this->Login->patchEntity($login, $this->request->getData());
        if ($this->Login->save($login)) {
            $this->Flash->success(__('Your login has been saved.'));
            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('Unable to add your login.'));
    }
    $this->set('login', $login);
}

```

}

add.ctp

# Add User

\<?php

```
echo $this->Form->create($login);
echo $this->Form->control('username');
echo $this->Form->control('password');
echo $this->Form->button(__('Save Article'));

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

```

?\>

Model/Login.php

\<?php namespace App\Model\Table; App::uses('AuthComponent', 'Controller/Component'); use Cake\ORM\Table; use Cake\Validation\Validator; class Login extends AppModel { public $validate = array('username' =\> array('rule' =\> 'notEmpty')); } ?\>

validation added in Login.php is not working.Please help
