How to get date drop downs automatically with form input CakePHP 3?

136 Views Asked by At

So I have already created a way to add testimonials and there is a section of the form to add a date of the testimonial. In my database table it is set up as a date type. On my form I only have:

<?= $this->Form->input('testimony_date'); ?>

In my table file in the model there is a validation:

    $validator
        ->add('testimony_date', 'valid', ['rule' => 'date'])
        ->requirePresence('testimony_date', 'create')
        ->notEmpty('testimony_date');

I mimicked this same procedure to add a presentation_date to a different form that goes to a different controller. The date drop downs were added to the testimonial add form automatically. The presentation form is not adding the dates automatically. I can get the drop downs if I make the form input like this:

<?= $this->Form->date('presentation_date'); ?>

The date drop downs for the testimonial form are filled out with a default of today's date. The presentation form doesn't have default values or a label when I make it $this->Form->date. My question is, why aren't drop downs automatically added like in the testimonial situation?

Is there something else I am suppose to add somewhere?

The testimonial files were created with the bake feature and the presentation files were created manually. I checked to make sure the form variable was spelled correctly.

2

There are 2 best solutions below

0
On BEST ANSWER

It looks like everything was fine, but for some reason the cache on my server was messing with how things were displayed. Once I cleared the tmp model folder, it fixed the issue. Like I said everything was mimicked (entity, table, controller, template/views). Anyway thank you all for your help.

0
On

Since you say 'presentation_date' goes to a different controller, I'm guessing that you have a 'testimony' table and a separate 'presentation' table?

The form class uses your table model to generate the right input template for the field in your table when you bake the template. So it works for 'testimony_date' because you have it defined in the model.

If you've 'mimicked' the usage in the testimony template, but you don't have an actual field 'presentation_date', Cake doesn't know how to pick an input template for it.

If you have a 'presentation' table with a 'presentation_date' date type, perhaps you haven't baked the model for it? Try baking the model (or 'all'), and then try putting

$this->Form->input('presentation_date',..)

in your view file (template file).

Note: if you bake 'all' to create the Model, Controller and Templates, careful that it doesn't overwrite your controller if you wrote your own.