# How to prevent having a dropdown menu in form when defining a field as date

**URL:** <https://discourse.cakephp.org/t/how-to-prevent-having-a-dropdown-menu-in-form-when-defining-a-field-as-date/7062>\
**Category:** Need Help\
**Created:** [January 5, 2020, 3:43pm UTC](https://discourse.cakephp.org/t/how-to-prevent-having-a-dropdown-menu-in-form-when-defining-a-field-as-date/7062 "2020-01-05T15:43:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bengatoh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bengatoh/32/1622_2.png) [@bengatoh](https://discourse.cakephp.org/u/bengatoh)\
**Post date:** [January 5, 2020, 3:43pm UTC](https://discourse.cakephp.org/t/how-to-prevent-having-a-dropdown-menu-in-form-when-defining-a-field-as-date/7062/1 "2020-01-05T15:43:41Z")

</div>

A field in model is defined as type “date”;  
I try to enter in form (.ctp) this data: \<?= date('Y-m-d') ?\>. When the form is displayed in order to fill it up, I have always have offered a dropdown menu! How to display and enter the today’s date (ex:2020-01-05), so people cannot scroll and change date??

\<?= $this-\>Form-\> input('date\_adhesion\_fadoq',['label' =\> "Date du jour à l'inscription" , date('Y-m-d')]) ? I can freese the Year with "minYear" and "maxYear" but not month (M) and day (d);

---

<div class="post-metadata">

**Author:** ![dakota](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dakota/32/1421_2.png) [@dakota](https://discourse.cakephp.org/u/dakota)\
**Post date:** [January 5, 2020, 7:31pm UTC](https://discourse.cakephp.org/t/how-to-prevent-having-a-dropdown-menu-in-form-when-defining-a-field-as-date/7062/2 "2020-01-05T19:31:22Z")

</div>

Why do you want to display a field that the user cannot change?

You need to tell CakePHP that the field type shouldn’t be the default, and that it should be read only. Something like `<?= $this->Form-> input('date_adhesion_fadoq',['label' => "Date du jour à l'inscription" , date('Y-m-d'), 'type' => 'text', 'readonly' => true]) ?>` should do it.

---

<div class="post-metadata">

**Author:** ![bengatoh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bengatoh/32/1622_2.png) [@bengatoh](https://discourse.cakephp.org/u/bengatoh)\
**Post date:** [January 8, 2020, 6:53am UTC](https://discourse.cakephp.org/t/how-to-prevent-having-a-dropdown-menu-in-form-when-defining-a-field-as-date/7062/3 "2020-01-08T06:53:21Z")

</div>

Good morning Sir Dakota,

quick reply.

Explanation about \*(\*_Why do you want to display a field that the user cannot change)_ :

Registering a membership in our Application on CakePHP framework , has few steps so we don’t know how to assign a field in our database defined as datatype “date”, to a value such as "now’ (Today YYYY-m-d) on create…

I am a neophyte in CakePHP (on training learning by Trial On Error (TOE) and luckily we have someone like you to help us.

Your solution works! … but as you said has not much sense,

Other…

- Likewise we want to validate a new member Birth date for being 50 and + to get registered card and we do not know hot to do it.

- Our Database is working OK. However for example we want delete in table “activities” which occurred in 2015-2016; phpmyadmin, We get the message:

- ![image.png](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/d/d32c6253b4e741b604b711e7dd6c2ea055008490.png)

Thanks for your patience and quick reply.

We do much appreciate this excellent type of service

Benoit

P.S. I included the files in case you have a clue or direct me to help

(Attachment airocon\_fadoqformation \_ Creation SQL Request\_phpMyAdmin 4.8.pdf is missing)

(Attachment Database - Data\_Dictionary\_phpMyAdmin 4.8.pdf is missing)

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [January 8, 2020, 2:38pm UTC](https://discourse.cakephp.org/t/how-to-prevent-having-a-dropdown-menu-in-form-when-defining-a-field-as-date/7062/4 "2020-01-08T14:38:32Z")

</div>

To set the created field to today’s date, look at the [timestamp behavior](https://book.cakephp.org/3/en/orm/behaviors/timestamp.html).

You don’t say specifically which version of Cake you’re using, but `ajouter.php` is almost certainly not the right place to be implementing your model.

You are getting that “foreign key constraint fails” error when deleting records manually with PHPMyAdmin? This is not clear. Anyway, that’s because your database has constraints and you’re trying to remove a record that other records refer to. Make sure that you delete the references first. In Cake, that can often be as simple as enabling the “dependent” option on table associations, though that should only be done when you understand the implications, as it’s possible for that to delete things that shouldn’t have been if it’s just applied indiscriminately.
