PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] CakePHP 3: Hidden DateTime input field is not accepting date

 February 22, 2022     cakephp, cakephp-3.0     No comments   

Issue

I have a datetime field in my database called start_time that I would like updated with the current datetime when a user performs a specific action. I would also like this field to be hidden in the edit view.

I have tried a number of combinations in the form in my edit view as well as reading through some other similar questions on this but its not working (or i am not fully understanding other posts).

Just some samples of combinations I have tried include:

echo $this->Form->hidden('start_time', ['value' => date('Y-m-d H:i:s')]);
echo $this->Form->input('start_time', ['type'=>'hidden','value' => date('Y-m-d H:i:s')]);

If I leave the baked form view of echo $this->Form->input('start_time') I see that individual [year], [month], [day] select options are created in the HTML, just wanting to understand if I need to add 6 hidden form options to cover start_time[year], start_time[month], etc... to cover all the Y-m-d H:i:s fields of a MYSQL datetime format...

Any help is appreciated. Thanks! mk


Solution

Solution for my issue was actually in the answer found here. Basically adding the beforeMarshal call into my [mymodel]Table.php and once I did this correctly the valid datetime format was added into my DB field.

Apologies for somewhat duplicate question.



Answered By - mk97
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing