I'm developing request forms for a library setting - anonymous users requesting books to buy, borrow, etc.

I have a webform set up which assigns "today" to the date ordered field. A second date field is called "Needed_By" and this date is not mandatory. If I use the form to create a record, then edit it and view it using Webform's native results tabs, everything is normal.

When I create a Webform Report that uses that Webform, and then edit any given record without making changes and then save it, the "Needed_by" field will display as today's date in the report, even if the field in the original webform is blank.

This is using Webform 7x-3.20, Drupal 7.24.

Suggestion greatly appreciated.

Bobb Menk
MIT Lincoln Laboratory Library

Comments

bmenk’s picture

Component: Documentation » Code
bmenk’s picture

I think I've found the problem, but I don't know enough code to try to fix it.

If there's an explicit date set in my Needed_by filed everything works as expected. However if the field is empty rather than NULL Webform Report seems to force a display of today's date. It isn't actually changing the value in the field, it's just displays today's date instead of nothing.

Thanks

Bobb Menk

bmenk’s picture

A staff member here found the issue in webform_report.inc as described below.

Any chance of this getting vetted and perhaps rolled into a patch? Or even better into next revision of the module?

Under normal use, the "today's date" problem (wherein the "Needed By" date is left null in the original request but is set to today during display) is not saving those edits to the database. Therefore, went searching in sites/all/modules/webform_report/webform_report.inc for the loop(s) that render those values out to the page. Found ~line 906 and changed to this:

// ccm hack, 2014.10.01 -- checks for empty needed_by (or other) dates
if(strlen($raw[0]) >0){
//if there was a string, use it
      $ts = new DateTime($raw[0]);
} else {
//no string in raw[0], so ts is null
$ts = null;}
    }
    // otherwise get submission timestamp
    else {
      $ts = new DateTime();
      $ts->setTimeStamp($raw[0]);
    }
    // if valid date
//ccm hack, adds null check to $ts if
    if ($ts && $ts !== null) {
      $format = $column['format'];
      // set default format if none given
      if (empty($format)) {
        $format = 'Y-m-d';
      }
      // format the date
      $out = array('data' => $ts->format($format), 'field' => $column['cid'], 'sort' => $ts);
    } else {
//ccm hack
//ts wasn't set or was null
//send same thing but with a blank ts
$out = array('data' => '','field' => $column['cid'], 'sort' => $ts);
}

Bobb Menk