In my understanding a validator validates input.
It should and will never change input to be displayed in another format.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Mark Murphy" <mmu...@cinci.rr.com>
To: <fw-general@lists.zend.com>
Sent: Friday, January 15, 2010 7:57 PM
Subject: [fw-general] Zend Date


I am a total newbie here. Trying to learn ZF. Have doe the Quickstart tutorial, and also created a simple application using the concepts learned from that. I am now trying to tweak it. One thing I need to know is how to use Zend_Date. I have a date in the database that I am displaying on a Zend_Form using a text field. Here is the definition of the field on my form:

       // Add Drive Date
       $this->addElement('text', 'driveDate', array(
           'label'         => 'Date',
           'required'     => true,
           'filters'     => array('StringTrim'),
           'validators' => array(
               array(
                   'validator' => 'Date',
                   'options'    => array('date_format' => 'n/j/Y')
               )
           )
       ));

The date shows on the form in YYYY-MM-DD format, but I would like to see it in MM/DD/YYYY format. It also expects any dates entered to be in YYYY-MM-DD format despite the validator listed above. I am guessing that using Zend_Date is what I want to do, but when I create a Zend_Date object from the field upon retrieving it from the database, the format includes a time (12:00am) which I don't want. So what am I missing? How can I get the Date validator to function properly? How can I display the date without the time, and how do I get a modified date back into the database?

Reply via email to