Unable to display error message for cakephp3 bootstrap-ui

450 Views Asked by At
  • [x] bug
  • BootstrapUI Version: v0.5.0
  • Bootstrap Framework Version: v3.3.6
  • jQuery: 3.0.0-rc1
  • Platform and Target: Google Chrome, Apache

What you did

App\View namespace App\View;

use Cake\View\View;
use BootstrapUI\View\UIViewTrait;

class AppView extends View
{
    use UIViewTrait;

    /**
     * Initialization hook method.
     */
    public function initialize()
    {
        //render the initializeUI method from the UIViewTrait
        $this->initializeUI();
        $this->layout('default');
    }
}

controller/create function

$student = $this->Students->newEntity($data['Students']);
if (!$this->Students->save($student)) {
    $isOkay = false;
    debug($student);
}

create.ctp

<?php echo $this->Form->create(null, ['align' => [
   'sm' => [
       'left' => 4,
       'middle' => 8,
       'right' => 12
   ],
   'md' => [
       'left' => 2,
       'middle' => 6,
       'right' => 4
   ]

], 'id' => 'myform']); ?>

<fieldset id="page-1">
   <legend>Student Profile</legend>

   <?php
       echo $this->Form->input('Students.name', [
           'label' => 'Full name'
       ]);
   ?>
</fieldset>

<button class="btn btn-primary" type="submit">Save</button>
<?php echo $this->Form->end(); ?>

StudentsTable.php

public function validationDefault(Validator $validator) {
  $validator
    - > integer('id') - > allowEmpty('id', 'create');

  $validator
    - > notEmpty('name', 'Username must input.');
}

Expected Behavior

I expect I will getting error block beside the field.

Actual Behavior

The error message is missing from page, but I can found it in controller.

Error message

1

There are 1 best solutions below

0
On BEST ANSWER

You need to pass the $student variable from controller to view create.ctp. Also you need to pass $student variable into the form you want to display errors. In you case it will be:

$this->Form->create($student, ['align' => [...

Note: in both case $student variable should be an entity of StudentsTable.php.