I’ve run into a strange problem. So strange that I’m having to devise a workaround for now since I have no time to investigate it further.
My database table has a date field that allows null, with default null.
XPDO can insert and update to the field, but when you try to set the value back to an empty string (via a form interface), it refuses. It keeps the existing value.
I’ve followed the code all the way thru MakeForm (yeah yeah I know) and here’s where the rubber meets the road:
$object->fromArray($classVal, '', true);
It’s calling the fromArray() method of an XPDOObject.
I’ve echo’d out $classVal and the desired value is indeed empty, so I can only assume that there is some perfect storm of date field type and allow null preventing the value from being set back to empty.
My workaround involves doing a force update to NULL, since even an empty string will not do the trick:
$xpdoObject->set($field,NULL);
$xpdoObject->save();
for each date field (no biggie).
I wish I had time to dive into this to see what aspect is causing the problem.
Oh, and I know you’re going to want to see the XML:
<field key="field_name" dbtype="date" phptype="date" null="true" />
UPDATE:
I ended up working waaay around the problem by turning all empty $_POST vars into true NULL values. Fingers crossed...