DB date field set to NULL

mi micalb 21 Sep, 2012
I have a form set up with a Date picker, the DB has a column with DATE type and a NULL value, the form save to a DB table the date value.
When I create a new record using my form nothing is shown in the date picker field , and this is what i need BUT if I submit the form with nothing in the date box, after the 'save to db' action, the DB field is filled with 0000-00-00 and not NULL as expected.
After that if I try to edit the record with my form a wrong date is shown in the date picker (it should be empty).

I have tried to add a custom action to set the value of the 'date' variable to NULL before saving into DB but I always get 0000-00-00 in the DB.....

Is there a way to save a NULL into my date field ?

Michele
mi micalb 22 Sep, 2012
Ok, my fault, the Custom action was set to Mode 'view' instead of 'Controller', after that the code below in the Custom action lead to a NULL in the saved DB field.

<?php 
if ($form->data['com_val'] == '') 
{
$form->data['com_val'] = NULL ;
}

if ($form->data['com_cliente'] == '') 
{
$form->data['com_cliente'] = NULL ;
}
?>




Michele
This topic is locked and no more replies can be posted.