Hi,

I installed webform 7.x-3.3-beta1 on Drupal 7 beta1 and created a webform that contains a 'file' component.
Whenever I leave the file field blank and submit the form, I get the following error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'data' cannot be null: INSERT INTO {webform_submitted_data} (nid, sid, cid, no, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] => 3 [:db_insert_placeholder_1] => 15 [:db_insert_placeholder_2] => 12 [:db_insert_placeholder_3] => _old [:db_insert_placeholder_4] => ) in webform_submission_insert() (line 110 of ...\sites\all\modules\contrib\webform\includes\webform.submissions.inc).

In webform/includes/webform.submissions.inc we have:

function webform_submission_insert($node, $submission) {
  ...
  foreach ($submission->data as $cid => $values) {
    foreach ($values['value'] as $delta => $value) {
      db_insert('webform_submitted_data')
        ->fields(array(
          'nid' => $node->nid,
          'sid' => $submission->sid,
          'cid' => $cid,
          'no' => $delta,
          'data' => is_null($value) ? '' : $value,
        ))
        ->execute();
    }
  }
  ...
}

To fix the problem I changed:

'data' => $value

to:

'data' => is_null($value) ? '' : $value,
CommentFileSizeAuthor
webform.submissions.inc_.patch623 bytesVladRM

Comments

quicksketch’s picture

Priority: Major » Normal
Status: Active » Fixed

Thanks. Ultimately it'd probably be better to not make empty entries into the database at all, but this patch makes the D7 version match the functionality of the D6 version, which enters empty rows for empty file fields also. Committed. I'm rolling a 3.4 release to fix lingering issues discovered, this will be included in it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.