Invalid argument supplied for foreach() in C:\Program Files\Apache Group\Apache2\public_html\drupal-5.1\sites\all\modules\simplenews\simplenews.module on line 372.

simplenews_validate_taxonomy function assumes $taxonomy to be an array.
In the case I have - it isn't.

Have changed the code to the following.

function simplenews_validate_taxonomy($taxonomy) {
  $vid = _simplenews_get_vid();
  $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid);
  while ($tid = db_fetch_object($result)) {
    $tids[] = $tid->tid;
  }
  $taxes = array();
  # ADDED is_array()
  if (is_array($taxonomy)) { 
  foreach ($taxonomy as $tax) {
    $taxes[] = $tax;
  }
  } else {
    $taxes[] = $taxonomy;
  }
  return array_intersect($tids, $taxes);
}

Comments

sutharsan’s picture

Please describe your case. What modules have you activated that affect the taxonomy? Perhaps the cause of the problem is found there.

remy.honig’s picture

I got the same error. I suspect the category module to cause this error.

sutharsan’s picture

Status?

holgerd’s picture

I had the same problem and the code provided above made the error message go away (when sending out the test e-mail).

sutharsan’s picture

Status: Active » Closed (won't fix)

This could be a work-around, but if the problem is caused by Category module it should be solved by Category module.
See this issue for the status: http://drupal.org/node/115693