Re: formbuilder dateToDatabaseCallback problem

From: Date: Thu, 11 Jan 2007 11:55:14 +0000
Subject: Re: formbuilder dateToDatabaseCallback problem
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26324@lists.php.net to get a copy of this message
I solved my problem. It was my silly mistake. In effect the callback was not called because in that place there was not need for that. Being an ajax enabled application the saving operation are made by another function with another formbuilder function to configure, not the one used for visualization and the other one missed the formBuilder->dateToDatabaseCallback = 'myArray2Date'; configuration. Thank you for your time and your answers. On 1/11/07, Justin Patrin <papercrane@gmail.com> wrote:
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) {
    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();
... 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. 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
-- Justin Patrin


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