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
Theme issue?
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:
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.My theme - and messages
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:
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):
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!!
drupal_set_message not working on "validate"
I have the same problem, I am developing an application that usess drupal_set_message and use it on hook_nodeapi when $op = validate.
Any suggestions?