When users try to upload files using Filefield, they get the following message.

An error occurred:

<br> <b>Fatal error</b>: Cannot pass parameter 1 by reference in
>b>/var/www/html/drupal/sites/all/modules/filefield/filefield.module</b> on line <b>852</b> <br>

Here's the function that contains line 852:

function filefield_js() {
  // Parse fieldname from submit button.
  $matches = array();
  foreach(array_keys($_POST) as $key) {
    if (preg_match('/cck_filefield_(.*)_op/', $key, $matches)) {
      $fieldname = $matches[1];
      break;
    }
  }

  $node = (object)$_POST;
  $field = content_fields($fieldname, $node->type); // load field data

  // Load fids stored by content.module.
  $items = array();
  $values = content_field('load', $node, $field, $items, FALSE, FALSE);
  $items = $values[$fieldname];

  // Load additional field data.
  filefield_field('load', $node, $field, $items, FALSE, FALSE);

  // Handle uploads and validation.
  _filefield_widget_prepare_form_values($node, $field, $items);
  _filefield_widget_validate($node, $field, $items);

  // Get our new form baby, yeah tiger, get em!
  $form = _filefield_widget_form($node, $field, $items);

  foreach (module_implements('form_alter') as $module) {
    $function = $module .'_form_alter';
    $function('filefield_js', $form);  // <= LINE 852
  }
  $form = form_builder('filefield_js', $form);

  $output = theme('status_messages') . drupal_render($form);

  // Send the updated file attachments form.
  print drupal_to_js(array('status' => TRUE, 'data' => $output));
  exit();
}

The file uploads, but the error message is disturbing. I'm marking this as critical because I need to launch my site ASAP, but can't as long as this error message is appearing.

Please help?

Comments

jpetso’s picture

Status: Active » Closed (fixed)

This is not an error in filefield but in one of the modules that you use. One of them implements hook_form_alter() and takes &$form_id as first parameter, which it should not because the $form_id value is not supposed to be modified. The ampersand before the $form_id parameter is therefore wrong (e.g. mymodule_form_alter(&$form_id, &$form) should rather be mymodule_form_alter($form_id, &$form)).

You could insert the following line just before the line that throws the error:

    drupal_set_message($function);

...and then call it again. The error will still appear, but if you reload the page then you should be shown the list of hook_form_alter() implementations that were called, and the last one in that list is the one that causes the error.

I'm going to close this issue because filefield is not responsible for it.