how to give validation for drop down box in cakephp3.6.7 please help me
thanks & regards
how to give validation for drop down box in cakephp3.6.7 please help me
thanks & regards
Do you have read this manual?
https://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-validators
Maybe this example can help:
Table: users;
Fields : id, username, role_id;
Validation
$validator
->maxLength(‘name’,150)
->notEmpty(‘name’, ‘Please fill this field’);
$validator
->notEmpty('role_id', 'Please select this options');
Sometime, I do like this for dropdown to make default empty value.
echo $this->Form->input('role_id',['options'=>$roles, **'empty'=>'(Select)'**]);
sorry about my language
thanks yar,
but which file i’ll put that $validator variable…?
UsersTable.php
Please check above file in your project if you baked your models.
Regards,
Ashish
I think you should use this for get full code generated by cake bake.
https://book.cakephp.org/3.0/en/bake/usage.html
Script
bin/cake bake all [tables name]
Example
bin/cake bake all users
thank you guyzzzz…,
but i cant fetch multiple checkbox value from database
it stored like (1,3) in database but fetching not showing using implode and explode functions in cakephp3.6.7
plz help me
I think this the basic idea.
You can found it at https://book.cakephp.org/3.0/en/views/helpers/form.html#options-for-select-checkbox-and-radio-controls
$selected = [1, 3];
$options = [1, 2, 3, 4, 5];
echo $this->Form->select(
'rooms',
$options,
[
'multiple' => true,
'value' => $selected
]
);