Re: formbuilder dateToDatabaseCallback problem

From: Date: Thu, 11 Jan 2007 08:39:26 +0000
Subject: Re: formbuilder dateToDatabaseCallback problem
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26319@lists.php.net to get a copy of this message
This is a very strange behaviour I know. The only thing I want is force formbuilder to accept empty date values, but I'm using PostgreSQL and it does not accept 0000-00-00, it wants a real empty value. Here there is the code I have used: /* * date callback functions used by DB_DataObject_FormBuilder */ function myDateOptions($field, &$fb) { return array('format' => 'd-m-Y',
                'addEmptyOption' => true,
                'emptyOptionText' => '--',
                'minYear' => 1977,
                'maxYear' => 2020);
} function myDate2Array($date) { if ($date == null || !strlen($date)) {
       return array();
} else {
       return DB_DataObject_FormBuilder::_date2Array($date);
} } function myArray2Date($date) { echo 'myArray2Date works'; if ($date['Y'] == ' ' && $date['m'] == ' ' && $date['d'] == ' ') {
       return '';
} else {
       return DB_DataObject_FormBuilder::_array2date($date);
} } .... /* * formBuilder creation and configuration */ $formBuilder =& DB_DataObject_FormBuilder::create($db); $formBuilder->enumFields = array_keys($field_options[$table]); $formBuilder->enumOptions = $field_options[$table]; $formBuilder->linkDisplayLevel = 0; $formBuilder->clientRules = true; $formBuilder->createSubmit = 0; $formBuilder->ruleViolationMessage = '%s: formato dati non corretto'; $formBuilder->addFormHeader = false; $formBuilder->elementTypeAttributes = array('integer' => array('size' => 5)); $formBuilder->dateOptionsCallback = 'myDateOptions'; $formBuilder->dateFromDatabaseCallback = 'myDate2Array'; $formBuilder->dateToDatabaseCallback = 'myArray2Date'; $formBuilder->fieldLabels = $field_labels[$table]; $form =& $formBuilder->getForm(); ... On 1/11/07, David Sanders <dsanders@baselinesolutions.com.au> wrote:
If your other callbacks work I don't see why myArray2Date wouldn't work? Paste your code in a paste site so we can see what your doing. Luca Giandoso wrote: I'm using php 5.1 and all the lastest pear packages. When setting: ... $formBuilder->dateOptionsCallback = 'myDateOptions'; $formBuilder->dateFromDatabaseCallback = 'myDate2Array'; $formBuilder->dateToDatabaseCallback = 'myArray2Date'; All of the above work except myArray2Date. I am sure the 'myArray2Date' is not called and that is callable. Any suggestions? --
     David Sanders


« previous php.pear.general (#26319) next »