Re: formbuilder dateToDatabaseCallback problem
| From: | Justin Patrin | Date: | Thu, 11 Jan 2007 11:04:00 +0000 |
| Subject: | Re: formbuilder dateToDatabaseCallback problem | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26323@lists.php.net to get a copy of this message | ||
On 1/11/07, Luca Giandoso <luca.giandoso@gmail.com> wrote:
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) {Well, this is the creation part. What gets output if you add this to your code right before you call process()? DB_DataObject::debugLevel(5); It should say: Field FIELDNAME then: DATE CONVERSION for using callback from VALUE Does it show those? You may want to just put a print_r in the FormBuilder code to know if your callback is still set right.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:-- Justin PatrinI'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