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

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);

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.

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,


  • 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.

    We tried some validation in Model (ajouter.php) but cannot make it work without (internal error). "Our coding is in file “ajouter.php”

  • 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

Thanks for your patience and quick reply.

We do much appreciate this excellent type of service


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)

To set the created field to today’s date, look at the timestamp behavior.

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.