Show message after submitting a form (Drupal 7)

Using Drupal 7.9.

I want to show a confirmation message to any anonymous user who submits a comment or uses the site contact form. The current situation is really awkward: if an anon user posts a comment, it will await moderation by me, but they see nothing but an unchanged article page; if a user sends a message, they just get sent to the home page.

I don’t know about web experts, but that makes me assume that it failed and I just wasted my time writing a comment or message that got silently discarded. This is surely a major oversight by the developers of Drupal.

So I want to show a custom message, something like “Your comment has been received and is awaiting moderation” and “Your message has been sent and you should receive a reply shortly”. I played around a bit with the Trigger module, and found that it can create custom messages for certain actions, including posting comments. But my message only showed up when I posted a comment while logged in: when testing it as an anon user, I got no message.

(Incidentally, I already have notes above the comment form and e-mail form, giving brief info for each. Users are made aware that moderation is in use, but I’m not openly admitting that they can assume that their comment has been received if the page doesn’t change!).

This should already be handled internally by the CMS. There should be a message outputted between the page’s title and the body copy that looks like this:

<div class="messages status">
Your comment has been queued for moderation by site administrators and will be published after approval.</div>

You can use CSS to highlight it or jQuery & CSS to really highlight it.

Andrew

No, I’m not getting that.

EDIT: This may help. If I make a comment while logged in, I get a message stating “your comment has been posted”. It seems that anon users get no messages apart from the red error messages (they show OK when they apply), while logged in users (well, user 1 at least) get the green messages.

Well, that’s strange… Check your permissions. I have a couple of plain vanilla Drupal 6 and Drupal 7 sites. The message status thing I posted earlier was from a Drupal 6 site. This is from a Drupal 7 site:

<div class="messages status">
<h2 class="element-invisible">Status message</h2>
Your comment has been queued for review by site administrators and will be published after approval.</div>

Permissions is the only thing I can think of that would affect it.

Also check the source html… Maybe for some reason it is hidden with CSS or something.

Andrew

It’s not in the mark-up. I double-checked that, even though I hadn’t hidden it.

What part of the permissions would/might affect the messages?

Yeah, I have no idea… I just did a little looking around to see if I could figure out how you could prevent the messages from occurring by accident but I can’t see how. I’m stumped?

Yes, me too, Andrew.

At least it explains why I couldn’t find any tutorials for how to do this, though! But one question has been replaced by another!

Thanks for replying anyway.

No worries… This is a weird one.

Are you using one of the OEM themes or are you using a custom or modified one? The really strange part is that you are getting the message when you are logged in. Can you post the html that the system is posting when you are logged in, including the div container, etc… Like the one I posted earlier.

Andrew

Yeah, certainly. When logged in and using the site contact form, for example, I got this:

<div id="messages"><div class="messages status">
<h2 class="element-invisible">Status message</h2>
Your message has been sent.</div>
</div>

I’m using a custom theme comprising a few modified template files and my own CSS files. I’m only serving Drupal’s own admin-related CSS and JS files to logged in users (ie, me): everyone else just gets my own CSS and, currently, no JS because I haven’t found a need for any yet. I wondered if this tactic was to blame, but modifying it didn’t fix this problem.

The problem occurs in two installations: one on a WAMPserver and the other (currently incomplete and accessible only to my IP) on a shared server. It is remotely possible that one or more of the settings and/or modules that are common to both installations is to blame, so my next step is to set up another installation on the local server and see if it happens again.

Have you tried testing by setting one of the OEM themes as default (like Bartik) to see if that brings back the message. That way you could rule out the Theme being the trouble.

Andrew

Yeah, I’ll try that as well. Although, I’ve used various themes during testing and I haven’t noticed anything different. I just assumed that it was like Wordpress blogs, which all seem to give no feedback when a comment is submitted.

I’ll get back to you later when I have access to my desktop (where WAMP is installed).

Progress of a kind.

I set up another Drupal installation in WAMP. Heart sank when same problem occurred! Tried, as a long shot, enabling JS (which is normally blocked in my browsers unless essential): no change. Tried, as a very long shot, enabling cookies (ditto, blocked unless essential): got the confirmation message!

So now I have to figure out why someone at Drupal thinks that everyone browses the web with cookies enabled (I never go out without trousers on, so why would I allow all cookies?!) and, more to the point, whether I can do anything to change this unnecessary behaviour. I suppose that it may be related to the cookies that are set when someone uses a form, but they are not required.

At least this explains the discrepancy between logged in and anon behaviour.

Right… of course,… I wonder if it’s a session cookie or a local cookie that they’re using.

The reason they need it is because when you submit the form it doesn’t submit to the same page, it submits to a switchboard (my term) that goes, ok, this guy just submitted and everything is good, let’s redirect him back to the page he came from. So my guess is that they are keeping that message sitting in a cookie so that it will be available when the page renders. After the page renders, the message is set to null.

That’s just my guess based on messing about with Drupal.