Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:46:44+00:00 2026-06-10T09:46:44+00:00

What’s the standard way to get rid of the three <select> elements and allow

  • 0

What’s the standard way to get rid of the three <select> elements and allow users to just type dates in a regular <input type="text"> control?

Requirements include:

  • Date format must be D/M/Y
  • Existing dates must be printed correctly
  • Cannot break date validation

I cannot find any reasonable documentation on this, just hacks in forum threads written by users as clueless as me xD

Clarification: Please note the CakePHP tag. I already know how to handle dates in regular PHP. I need help about the precise CakePHP mechanism I can use to adjust the framework’s default functionality (and I really mean adjust rather than override).

So far, I’ve added this to the model:

public $validate = array(
    'fecha' => array(
        array(
            'rule' => 'notEmpty',
            'required' => true,
        ),
        array(
            'rule' => array('date', 'dmy'),
        ),
    )
);

… and I’ve composed the field like this inside the view:

echo $this->Form->input(
    'Foo.fecha',
    array(
        'type' => 'text',
    )
);

… but all I can do with this is reading and validating user input: it won’t print previous date properly and it won’t store new date properly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:46:45+00:00Added an answer on June 10, 2026 at 9:46 am

    Here’s a summary of my findings. It seems that the appropriate mechanism is using Model Callback Methods to switch between two date formats:

    • Database format, e.g.: 2012-08-28
    • Display format, e.g.: 28/08/2012

    Steps:

    1. Add two utility methods to AppModel to convert between my custom format (aka “display format”) and MySQL’s default format (aka “DB format”).
    2. Add an afterFind() filter to my model that converts to display format when read from DB.
    3. Render the form control as 'type' => 'text'.
    4. Add a 'rule' => array('date', 'dmy') validation rule to the field inside the model.
    5. Add a beforeSave() filter to my model that converts to DB format right before saving.

    These steps can be encapsulated with a behaviour that implements the afterFind() and beforeSave() callbacks and possibly some others like beforeFind(). The behaviour can be applied directly to AppModel and will take care of traversing data arrays to convert dates between both formats (if the model has an attached table). The code is not trivial but can be done and it makes it all transparent.

    Drawbacks:

    • Makes code MySQL-only (but, isn’t it MySQL-only already?)
    • Makes it difficult to localize.
    • If you need to do date math, you find yourself with human-readable strings.

    It would be more rock-solid to be able to use three formats:

    • Database format, e.g.: 2012-08-28
    • Display format, e.g.: 28/08/2012
    • PHP internal format, e.g. Unix timestamps or DateTime objects

    Sadly, the CakePHP core is not designed for that and it all starts getting too complicate if you attemp to implement it this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.