Calc in repeated group causes corrupt form display.

Discussion in 'Professional Support' started by bggann, Jun 16, 2017.

  1. bggann

    bggann Member

    Level: Professional
    I've got a form with repeated groups.
    In the repeated groups are calc element that depends on the data in that group as well as the parent group.
    All works well till I hit repeated group 6 (in other words I can have 5 repeated groups).
    On the 6th group, if I trigger a calculation (ajax), the calculated group display appears briefly but then is overwritten with a view of the home page of the site.

    In other words, where the calculated element should be displayed, you see the front page of the site.
    The error is systematic. I use the same calculation in up to 4 fields in the repeated group (I do not use the results of one calc in another calc, I repeat the base calculation). All of those fields are replaced with the "home page" display.

    If I ignore the corrupt display, and submit the record, it actually writes to the database correctly, so this appears to be something related to ajax (maybe?) or an overflow (maybe?).

    Here is the code that is in the calc element.
    I've attached a couple screen shots - one showing the correct display, the other showing the corrupt display.

    Looks like some kind of overflow????
    //Code for picking Rate
    // Duplicating calculation of time here to force calculation
    //dumpmessage('Start flight seat cost');
    $db = JFactory::getDbo();
    $start_time = explode(",",'{daily_log_7_repeat___seat_start_time_raw}');
    if ( empty($start_time[1])) {$start_time[1]="00";}
    if ( empty($start_time[0])) {$start_time[0]="00";}
    $start_time_text = implode(':',$start_time);
    $start_time_sec = strtotime('01/01/1980 '.$start_time_text.':00');
    $stop_time = explode(",",'{daily_log_7_repeat___seat_stop_time_raw}');
    if ( empty($stop_time[1])) {$stop_time[1]="00";}
    if ( empty($stop_time[0])) {$stop_time[0]="00";}
    $stop_time_text = implode(':',$stop_time);
    $stop_time_sec = strtotime('01/01/1980 '.$stop_time_text.':00');
    if ($stop_time_sec < $start_time_sec) {
    $stop_time_sec += 86400;

    $flight_hours_raw = (float)($stop_time_sec - $start_time_sec)/3600 ;
    $flight_hours = round ( $flight_hours_raw,2);
    //dump($flight_hours,'flight hours');

    $n_number = '{daily_log___aircraft_n_number_raw}';

    if (empty($n_number) or empty($flight_hours)) {
    //dumpmessage('Exiting flight cost');
    // Exit out
    else {
    $query_string = 'SELECT aircraft_base_flight_rate FROM aircraft WHERE id = "'.$n_number.'"';
    $rows = $db->loadObjectList();
    foreach ($rows as $row) {
    $rate = $row->aircraft_base_flight_rate;
    $total_cost = (float) $rate * $flight_hours;
    //dump($total_cost,'total cost');
    //dump($flight_hours,'flight hours');
    //dumpmessage('end seat flight cost');
    return $total_cost;
    This is correct. Seat Flight Start Time triggers calculation of Seat Flight Time and SEAT flight cost.
    This is as loaded from the database.
    This is the corrupted one. This happens after ajax
    Notice how the calc feilds have be replaced with the site front page
  2. bggann

    bggann Member

    Level: Professional
    Further information
    If I turn off AJAX on the problem feilds, the issue does not appear. Is this an ajax overflow problem?
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    I suspect it's probably something like max_input_vars, if you have a lot of elements in your repeat.

    Try doubling it in your PHP ini.

    -- hugh
  4. bggann

    bggann Member

    Level: Professional
    Yep - you are right - I ran into this problem before - oh fickle memory. Increased max variables in php.ini and it resolved.
    cheesegrits likes this.

Share This Page