Search code examples
validationcakephp-3.0formhelper

How to display validation message for select box in CakePHP 3?


Below you can see my model and view. Can't figure out how to display validation error message. How do I do that? All other validation messages for input fields are displayed as expected.

class ProjectsTable extends Table {
    public function validationDefault(Validator $validator) {
        $validator->requirePresence('language');
        return $validator;
    }
}
<?php echo $this->Form->select('language', [
    'option' => 'value',
    '' => 'Select'
], ['default' => '']); ?>

Solution

  • Another possibility is to use $this->Form->input() instead of select().

    <?php
    $this->Form->input('language', [
        'type' => 'select',
        'options' => [
             'option' => 'value'
        ]
    ]);
    ?>