I'm working on a module (which I have briefly described here), and want to redirect the output while displaying a message.

In short, I use the nodeapi hook and "validate" switch to check whether the node is available for editing or not (unavailable means it has been logically locked by another user). If the node is not available, then I want to display the node in "view" mode, not in "edit" mode, with a warning message.

To do this, here is what I have done:
drupal_set_message(t('This document is already checked out by another user');
drupal_goto('node/'. $node->nid);

Very simple! The only trouble is that, although the drupal_goto works fine, and displays the node in "view mode" which is what I want, there is no sign of the message (I want something like the message that you get after updating)

Am I not using drupal_set_message correctly or is this a bug?

Many thanks for your help

Comments

dries’s picture

What theme are you using? The messages are made available to the theme, but it is the theme's task to visualize them. You can print them in your theme using:

 print theme_status_messages();

If that doesn't work, I suspect something is wrong with your PHP's sessions (or the configuration thereof). The function drupal_set_message() stores the messages in a session variable, and only clears them after they have been visualized.

joel_guesclin’s picture

I'm using the Chameleon theme, in Drupal 4.5.0.
I'm running under Apache 2.0.48 under Windows/XP (all this is local experimenting).

The message works when i don't use drupal_goto afterwards. In my nodeapi I also do this:

      case 'update':
        if ($node->checkout != '1') {
           db_query("DELETE FROM {checkout} WHERE nid = '%d'", $node->nid);
           }
        else {
           drupal_set_message(t('Remember that you have this document checked out'));
           }
        break;

This causes the node to display the message just above the "book has been updated" message in the same nice green box - just the way it should be.

The problem comes with my validate code (take no notice of crappy logic which is still incomplete, eg I've not yet done put timestamp into whencheckedout):

Drupal found this code suspicious and wouldn't let me put it in!

This was - as I said - working except for the messages.

I thought I should check the sessions configuration - realised that my Drupal .htaccess file had not been modified to take account of the fact that I'm running Apache2. So modified it accordingly and here is the session configuration (which I have not touched as far as I can remember)

# Overload PHP variables:

#
# If you are using Apache 2, you have to use
# instead of .
php_value register_globals 0
php_value track_vars 1
php_value short_open_tag 1
php_value magic_quotes_gpc 0
php_value magic_quotes_runtime 0
php_value magic_quotes_sybase 0
php_value arg_separator.output "&"
php_value session.cache_expire 200000
php_value session.gc_maxlifetime 200000
php_value session.cookie_lifetime 2000000
php_value session.auto_start 0
php_value session.save_handler user
php_value session.cache_limiter none
php_value allow_call_time_pass_reference On

This certainly changes the behaviour of my module - it causes Apache to crash!!

Sergio Beristain’s picture

I have the same problem, I am developing an application that usess drupal_set_message and use it on hook_nodeapi when $op = validate.

  1. My theme includes theme_status_messsage() to be sure that it was not the theme I even tested on the included bluemarine theme and still does not work.
  2. I use Apache ver 1 so I should not have to modify my .access

Any suggestions?