Bug #19291 [Opn->Bgs]: Month and year selected wrong if month = 00 in DB

From: Date: Fri, 17 Feb 2012 15:38:05 +0000
Subject: Bug #19291 [Opn->Bgs]: Month and year selected wrong if month = 00 in DB
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-8285@lists.php.net to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=19291&edit=1 ID: 19291 Updated by: borz_off@cs.msu.su Reported By: leonard-php-bugs at ottolander dot nl Summary: Month and year selected wrong if month = 00 in DB -Status: Open +Status: Bogus Type: Bug Package: HTML_QuickForm2 Operating System: Linux Package Version: 0.6.1 PHP Version: Irrelevant Roadmap Versions: New Comment: -Status: Open +Status: Bogus When you pass the date as a string, it is handled by strtotime() [1] first. Since neither '0000-00-01' nor '2002-00-02' is a valid date, strtotime() makes a guess what was really meant. If you want different behaviour, parse the date string yourself and feed an array as the default value, e.g.: array('field_birthday' => array('d' => 1, 'M' => 0, 'Y' => 2002)) [1] http://ru.php.net/strtotime Previous Comments: ------------------------------------------------------------------------ [2012-02-13 15:13:31] leonardjo Description: ------------ When the month for a date coming from a mysql database is unset (00) the month and year are incorrectly selected. A date '0000-00-01' will have the month december (12) preselected. A date '2002-00-02' will have the month december (12) and the year 2001 preselected. Test script: --------------- <?php if (!include_once('HTML/QuickForm2.php')) { echo 'cant find quickform'; exit; } if (!include_once('HTML/QuickForm2/Renderer.php')) { echo 'cant find quickform renderer'; exit; } foreach (array('0000-00-00', '0000-00-01', '2002-00-01') as $d) { $form = new HTML_QuickForm2('form_name'); $renderer = HTML_QuickForm2_Renderer::factory('default'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array( array('field_birthday' => $d))); $form->addElement('date', 'field_birthday', null, array('minYear' => 1920, 'format' => 'dMY', 'addEmptyOption' => true, 'emptyOptionValue' => 0)) ->setLabel('Birthday'); echo $form->render($renderer); } ?> Expected result: ---------------- Empty value preselected for month and the correct year (seems to be n - 1) ------------------------------------------------------------------------ -- Edit this bug report at https://pear.php.net/bugs/bug.php?id=19291&edit=1

« previous php.pear.bugs (#8285) next »