so i started playing with a cakePhp app, trying to make it work, but i can't make the form helper output the validation error messages on the field with the error.I am using the FriendsOfCake/bootstrap-ui plugin to make the form helper output bootstrap forms. Here is my model:
public function validationDefault(Validator $validator)
{
$validator
->integer('id')
->allowEmpty('id', 'create');
$validator
->notEmpty('name', 'Name should not be empty')
->scalar('name')
->requirePresence('name', 'create');
return $validator;
My controller method:
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
$this->Flash->success(__('V-ati inregistrat cu success'));
return $this->redirect($this->referer());
}
$this->Flash->error(__('The user could not be saved. Please, try again.'));
}
$this->viewBuilder()->setLayout('auth');
$this->viewBuilder()->setTemplate('register');
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
and my form:
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<?=
$this->Form->create('users',['url'=>['controller'=>'Users','action'=>'store']]),
$this->Form->control('name'),
$this->Form->control('email'),
$this->Form->control('password'),
$this->Form->submit('Trimite'),
$this->Form->end()
?>
</div>
</div>