I want to use a form with the option to upload files, so in webform, the field multfile is not mandatory. Everything works great, if users upload one or more files, but when they submit their entries without any uploads, the following error message is shown:

warning: Invalid argument supplied for foreach() in /www/htdocs/[.......]/sites/all/modules/webform_multifile/multifile.inc on line 571.

This message shows up three times (at the same time). Line 571 in multifile.inc is marked below:

/**
 * Format the output of text data for this component
 */
function theme_webform_display_multifile($element) {
  $output = '';
  foreach ($element['#value'] as $file) {                              <<<< Line 571
    if (!empty($file)) {
      $url = webform_multifile_url($file->filepath);
      if ($element['#format'] == 'html') {
        $output .= '<div class="multifile-file">';
        $output .= l($file->filename, $url);
        $output .= '</div>';
      }
      else {
        $output .= $file->filename . ': ' . $url . "\n";
      }
    }
  }
  return $output;
}

Any idea?

Comments

jelle_s’s picture

Status: Active » Fixed

this should fix it:

/**
 * Format the output of text data for this component
 */
function theme_webform_display_multifile($element) {
  $output = '';
  if (isset($element['#value']) && !empty($element['#value'])) { //->this sould fix it ;-)
    foreach ($element['#value'] as $file) {
      if (!empty($file)) {
        $url = webform_multifile_url($file->filepath);
        if ($element['#format'] == 'html') {
          $output .= '<div class="multifile-file"> ';
          $output .= l($file->filename, $url);
          $output .= ' </div>';
        }
        else {
          $output .= $file->filename . ': ' . $url . "\n";
        }
      }
    }
  }
  return $output;
}

This should be fixed in the latest dev version (download from git or wait at least 12 hours to download it from drupal.org). Can you confirm?

flirpkrahusel’s picture

Hi Jelle_S,

yes, it works perfectly, thank you very much!!

Sven

Status: Fixed » Closed (fixed)

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