Results 1 to 4 of 4

Thread: save_callback is called twice upon save in BE

  1. #1
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default save_callback is called twice upon save in BE

    This is a very frustrating problem.

    I have a save_callback on a field for a new rgxp called "month" this accpets and checks that the $varValue is in the format:
    01/1957

    if not it generates a format error. if the format is ok, then I create a date from that format using the $varValue, e.g.

    $objDate = new Date($varValue, $GLOBALS['TL_CONFIG']['monthFormat']); // this is a new format also added to Settings

    Then it returns the tstamp to the savecallback.

    However, I added a global $counter variable and incremented it, and this save_callback function is called twice. Now it works 100% in the first call, but of course now in the second call, it is called with the $varValue which is a timestamp, and of course that fails all the checking routines (as it's no longer in the format "01/1957" or "m/Y").

    I've done a backtrace and this is the callstack:

    global counter == 1;

    #0 YearMonth->saveYearMonth(01/1957, DC_ProductData Object ()) called at [/www/htdocs/w00fcf0a/system/drivers/DC_Table.php:2656]
    #1 DC_Table->save(01/1957) called at [/www/htdocs/w00fcf0a/system/modules/backend/DataContainer.php:329]
    #2 DataContainer->row() called at [/www/htdocs/w00fcf0a/system/drivers/DC_ProductData.php:681]
    #3 DC_ProductData->edit() called at [/www/htdocs/w00fcf0a/system/modules/backend/Backend.php:287]
    #4 Backend->getBackendModule(iso_products) called at [/www/htdocs/w00fcf0a/contao/main.php:120]
    #5 Main->run() called at [/www/htdocs/w00fcf0a/contao/main.php:230]


    global counter == 2;

    #0 YearMonth->saveYearMonth(-410230800, DC_ProductData Object ()) called at [/www/htdocs/w00fcf0a/system/drivers/DC_Table.php:2656]
    #1 DC_Table->save(01/1957) called at [/www/htdocs/w00fcf0a/system/modules/backend/DataContainer.php:329]
    #2 DataContainer->row() called at [/www/htdocs/w00fcf0a/system/drivers/DC_ProductData.php:681]
    #3 DC_ProductData->edit() called at [/www/htdocs/w00fcf0a/system/modules/backend/Backend.php:287]
    #4 Backend->getBackendModule(iso_products) called at [/www/htdocs/w00fcf0a/contao/main.php:120]
    #5 Main->run() called at [/www/htdocs/w00fcf0a/contao/main.php:230]


    Why would the same routine be called twice upon save? That defeats the purpose of the save_callback (to format the data correctly).

  2. #2
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: save_callback is called twice upon save in BE

    Hmm, difficult. Is the onsave happening twice before the redirect?

    As a workaround; what if your function also accepts a tstamp?

    ps, probably Contao 2, but what Isotope version?
    ps2, can you make a similar field onto a default Contao table so we can rule out or pinpoint this to Isotope?

  3. #3
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: save_callback is called twice upon save in BE

    Hi Rudd. I would if I had time to debug contao. However, I make the field not check the format, just if it converts to a date correctly.

  4. #4
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: save_callback is called twice upon save in BE

    Then why not check if it is a timestamp and do nothing?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •