Zend_Dojo_Form_Element_DateTextBox Element's Value Is Set To 11/30/1899

Is the value of your Zend_Dojo_Form_Element_DateTextBox form element set to 11/30/1899?

The issue is actually Dojo related. You are most likely setting the value of the form element to '0000-00-00' using the populate() method of the Zend_Form or the setValue() method of the Zend_Form_Element. It so happens in a PHP/MySQL application, you provide a form field to enter the date to the user. The user supplies null value. You insert or update the record in your database. In the database the value is represented as '0000-00-00'. The next time you provide the form to the user, perhaps a data edit form, you populate the form with the values in the database and the user notices that the value is set to 11/30/1899.

Dojo sets the dateTextBox element's value to '11/30/1899', if you try to set it to '0000-00-00'.

To avoid this issue, before setting the form element's value, check if the date is valid. You can check if a date is valid in one line in your Zend Framework application.

<?php
 Zend_Date::isDate($myDate);
?>

The expression returns false if the date is not valid. If the date is not valid set null to the element's value.

Here's an snippet of code to illustrate the solution.

$birthdayInModel = $myModel['birthday'];
 
if (! (Zend_Date::isDate($birthdayInModel)) ) {
    $myZendDojoFormElementDateTextBox->setValue('');
}

About the author

Sudheer is an entrepreneur and software developer. Get more from Sudheer on Twitter.


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.