# How to give validation for drop down box and text box min length in cakephp3.6.7

**URL:** <https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617>\
**Category:** Need Help\
**Created:** [July 24, 2018, 9:07am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617 "2018-07-24T09:07:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dash](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@dash](https://discourse.cakephp.org/u/dash)\
**Post date:** [July 24, 2018, 9:07am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/1 "2018-07-24T09:07:32Z")

</div>

how to give validation for drop down box in cakephp3.6.7 please help me

thanks & regards

---

<div class="post-metadata">

**Author:** ![mzm](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mzm/32/1107_2.png) [@mzm](https://discourse.cakephp.org/u/mzm)\
**Post date:** [July 25, 2018, 4:52am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/2 "2018-07-25T04:52:54Z")

</div>

Do you have read this manual?  
[https://book.cakephp.org/3.0/en/core-libraries/validation.html#creating-validators](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 😁_

---

<div class="post-metadata">

**Author:** ![dash](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@dash](https://discourse.cakephp.org/u/dash)\
**Post date:** [July 25, 2018, 5:28am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/3 "2018-07-25T05:28:53Z")

</div>

thanks yar,  
but which file i’ll put that $validator variable…?

---

<div class="post-metadata">

**Author:** ![ashish\_onmobile](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ashish_onmobile/32/460_2.png) [@ashish\_onmobile](https://discourse.cakephp.org/u/ashish_onmobile)\
**Post date:** [July 25, 2018, 5:56am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/4 "2018-07-25T05:56:32Z")

</div>

UsersTable.php

Please check above file in your project if you baked your models.

Regards,  
Ashish

---

<div class="post-metadata">

**Author:** ![mzm](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mzm/32/1107_2.png) [@mzm](https://discourse.cakephp.org/u/mzm)\
**Post date:** [July 25, 2018, 6:39am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/5 "2018-07-25T06:39:53Z")

</div>

I think you should use this for get full code generated by cake bake.  
[https://book.cakephp.org/3.0/en/bake/usage.html](https://book.cakephp.org/3.0/en/bake/usage.html)

**Script**  
bin/cake bake all [tables name]

**Example**  
bin/cake bake all users

---

<div class="post-metadata">

**Author:** ![dash](https://avatars.discourse-cdn.com/v4/letter/d/7c8e57/32.png) [@dash](https://discourse.cakephp.org/u/dash)\
**Post date:** [July 25, 2018, 6:45am UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/6 "2018-07-25T06:45:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mzm](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mzm/32/1107_2.png) [@mzm](https://discourse.cakephp.org/u/mzm)\
**Post date:** [July 25, 2018, 1:49pm UTC](https://discourse.cakephp.org/t/how-to-give-validation-for-drop-down-box-and-text-box-min-length-in-cakephp3-6-7/4617/7 "2018-07-25T13:49:22Z")

</div>

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](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
    ]
);
```
