PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject_FormBuilder » Bug #7445

cannot default a date element to blank

Details

Submitted2006-04-20 21:52 UTC
Fromrbradford at khov dot com
Assignedjustinpatrin
StatusNo Feedback
PackageDB_DataObject_FormBuilder
PHP Version5.1.1
OSWindowsXP
Roadmaps(Not assigned)

Comments

[2006-04-20 21:52 UTC] rbradford at khov dot com

Description:
------------
I posted this on the HTML_QuickForm package, but maybe it
belongs here:

I have a form for handling help desk tickets. Each ticket
has a "due date" among other fields. This is not a required
field so I need to have the element default to blank and
store a NULL value if it is left blank. I got the form to
show the blanks using:

$builder->selectAddEmpty = array('due_date');

(I am using DB_DataObject_FormBuilder, however I believe
this deals with the HTML_QuickForm part of it)

If I go to edit a record the due date element ('d M Y')
populates with the current date by default.

I also tried using the setConstants method, but same thing.

Test script:
---------------
//Here's some code

$ticket = DB_DataObject::factory('hd_tickets');
$ticket->get($_POST['id']);
//...
$builder =& DB_DataObject_FormBuilder::create($ticket);
//...
$builder->dateElementFormat = 'd M Y';
$builder->selectAddEmpty = array('due_date');
//...
$form =& $builder->getForm();
//...
$renderer =& new HTML_QuickForm_Renderer_QuickHtml();
$form->accept($renderer);
//...
echo $renderer->toHtml($html_template);

Expected result:
----------------
If I load a ticket record that has a NULL value for a due date
then the due date element should show blanks and when it saved
with the date elements blank then it should keep the NULL
value

Actual result:
--------------
When I load a ticket record with a due date value of NULL then
the date element defaults to the current date. If I then
choose the blank options for each select and save it, the
value '0000-00-00' is stored.

[2006-06-16 08:34 UTC] michel dot dhooge at gmail dot com

You have to overload (maybe in your DO with fb_xxx):
var $dateFromDatabaseCallback = array('DB_DataObject_FormBuilder','_date2array');
var $dateToDatabaseCallback = array('DB_DataObject_FormBuilder','_array2date');

Both callbacks receive the fieldname so you can have a different behaviour for different fields even in a single Form. And you can always call the original callback from yours.

For "FromDB", you can simply sets it to null to always start with no value.

For "ToDB", you could also use the postProcessCB to remove the "0000-00-00" value.