PHP Error when I click on Preview
nocte - February 9, 2009 - 03:08
| Project: | Taxonomy Super Select |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
Hello,
When I have TSS enabled and I click on preview I get an PHP error:
Warning: Invalid argument supplied for foreach() in /var/www/web/html/site.tld/modules/taxonomy/taxonomy.module on line 70
Kind regards,
nocte

#1
I'm getting the same error on a fresh install. Thanks
#2
Add me as well; not on node-save, but node preview.
#3
I'm also getting this error with drupal 6.9, i'm getting this error when click on preview node button so please help us to resolve this error.
Please do this on urgent basis.
#4
I have used "theme_node_preview" into my theme template.php file and change some code in it and this error resolved.
Please use this code if it will solve your problem.
-----------------------
<?php
/* Overwrite theme_node_preview function*/
function (your-current-themename)_node_preview($node) {
$output = '<div class="preview">';
// My added code
if (!empty($node->taxonomy)) {
foreach ($node->taxonomy as $key => $term) {
// A 'Multiple select' and a 'Free tagging' field returns an array.
if (is_array($term)) {
foreach ($term as $tid) {
if($tid < 1) continue;
$taxonomy[$tid] = $tid;
}
}
$node->taxonomy[$key] = $taxonomy;
}
}
// custom code ends here
$preview_trimmed_version = FALSE;
// Do we need to preview trimmed version of post as well as full version?
if (isset($node->teaser) && isset($node->body)) {
$teaser = trim($node->teaser);
$body = trim(str_replace('<!--break-->', '', $node->body));
// Preview trimmed version if teaser and body will appear different;
// also (edge case) if both teaser and body have been specified by the user
// and are actually the same.
if ($teaser != $body || ($body && strpos($node->body, '<!--break-->') === 0)) {
$preview_trimmed_version = TRUE;
}
}
if ($preview_trimmed_version) {
drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "<!--break-->" (without the quotes) to fine-tune where your post gets split.</span>'));
$output .= '<h3>'. t('Preview trimmed version') .'</h3>';
$output .= node_view(drupal_clone($node), 1, FALSE, 0);
$output .= '<h3>'. t('Preview full version') .'</h3>';
$output .= node_view($node, 0, FALSE, 0);
}
else {
$output .= node_view($node, 0, FALSE, 0);
}
$output .= "</div>\n";
return $output;
}
// ----------------------------------------------
?>
Please remember to remove site cache.
#5
I can confirm the error on a completely fresh install.
Thanks for the previous hack but I hate to reproduce the whole preview logic just to add such specific code.
And I have a hard time understanding the CAUSE of the problem your hack solve.
It seems to lie in the way freetagings terms are not object in previews but my vocabulary as NO freetaging.
Is it possible to solve the problem at the MODULE level ?
And maybe give an explanation of the problem analysis "neerjasoftwares" did that would help somebody correct the problem at the MODULE level ?
why
if($tid < 1) continue;for example ? what's special about negative tid or the zero one ?thanks a lot for you time.
#6
Try this http://drupal.org/node/326614#comment-1431404
Cheers
#7
subscribe
#8
I had the same issue. Here's a patch I made to fix it for the 6-1 branch
#9
Here's an alternative patch, taken from http://drupal.org/node/326614#comment-1866476.