Hi,

Lately I seem to be getting a lot of these errors when viewing a node or today after creating a contact webform. Just when viewing the form I getting the following numerous times:

implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in /home/public_html/sites/all/modules/views/plugins/views_plugin_argument_default_php.inc(48) : eval()'d code on line 4.

In dblog:

Location http://www.mysite.com/contact
Referrer http://www.mysite.com/node/3191/edit

Did a good search on our forums, but does not seem to have appeared before. Do you perhaps have an idea what could be causing this please?

Look most forward to any reply, and thank you.
Lilian

Comments

liliplanet’s picture

Status: Active » Closed (fixed)

Found the answer : Since the views module emits this error, it means one of your custom views has an invalid argument passed. Try disabling their blocks e.g or delete them altogether and see.

I've disabled all blocks and the error went away. Now to find the invalid argument :)

merlinofchaos’s picture

It's not the argument that's invalid (well, it probably is) but that PHP COde you have in a validator is not properly written and is crashing. You need to go through your views and look for validators using the PHP Code type and see which of them have an implode() on line 4. Then have it check to make sure it's imploding the right thing.

liliplanet’s picture

Thank you MerlinofChaos .. I found it, had 2 arguments for 1 block, deleted it and now all is fabulous!

Most appreciate your reply :)
Lilian

wOOge’s picture

Solution for me:

Not sure if it's related but I created a custom module to rename the "Save" button — but that module also removed the "edit" and "delete" buttons of the node's form. Disabling my custom module (or re-coding it so it doesn't remove the delete and edit buttons) fixed the problem for me.

knalstaaf’s picture

I'm using arguments as well, as a way to show related items by taxonomy (source: Using Views 2 and Drupal 6 to Create a Related Pages Block).

The guy who wrote the mentionned tutorial (which has been very helpful in my case) uses this PHP-code in the argument (in the appropriate View » Arguments » Taxonomie: Term ID » Provide default argument » PHP code):

$node = node_load(arg(1));
if ($node) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, 6);
foreach ($terms as $tid => $term) {
$tids[] = $tid;
}
return implode ("+", $tids);
}
return false;

The second line of that code triggers that error message. The solution is to replace that line (if ($node) {) with if ($node->type == 'episode'), in which "episode" is the content type. So eventually, the code should look like this:

$node = node_load(arg(1));
if ($node->type == 'episode') {
$terms = taxonomy_node_get_terms_by_vocabulary($node, 3);
foreach ($terms as $tid => $term) {
$tids[] = $tid;
}
return implode ("+", $tids);
}
return false;

This solution (posted by Brad) saved me (and probably many others) a lot of time!

knalstaaf’s picture

In another project I still had a similar error nonetheless. In this case a taxonomy term isn't required, so the user can select "none" as a term or simply leave that field or option list open. The original code couldn't really handle this.

Original code (used in the appropriate View » Arguments » Taxonomie: Term ID » Provide default argument » PHP code):

$node = node_load(arg(1));
if($node->type == 'episode') {
    foreach($node->taxonomy as $term) { $terms[] = $term->tid; }
    return implode('+', $terms);
} else { return; }

A colleague solved the issue by modifiying the code to this:

$node = node_load(arg(1));
if($node->type == 'episode') {
    foreach($node->taxonomy as $term) { $terms[] = $term->tid; }
    if($terms != ""){
    return implode('+', $terms);
    }
} else { return; }
bryancasler’s picture

I'm using the following code

1	$node = node_load(arg(1));
2	if($node){
3	foreach (field_get_items('node', $node, 'field_tags') as $term ) {
4	  $terms[] = $term['tid'];
5	}
6	return implode('+', $terms);
7	} else { return; }

It is telling me I have "Invalid argument supplied for foreach() in eval() (line 3..."

I've looked over the documentation, am I missing something?
http://www.davereid.net/content/hlkd7fotw-field-get-items
http://api.drupal.org/api/drupal/modules--field--field.module/function/f...

bryancasler’s picture

Dave Reid's code seemed to work for me, and I was able to keep. $node
http://drupal.org/node/1023456#comment-3934504

if (arg(0) == 'node' && ($node = node_load(arg(1))) && node_access('view', $node) && $items = field_get_items('node', $node, 'field_tags') {
  $tids = array();
  foreach ($items as $term) {
    $tids[] = $term['tid'];
  }
  return implode('+', $tids);
}