Hi folks,

Is there anyway to set a "drupal message" on a link I'm putting in? it is a link to a certain page, and I want, when someone clicks that link, to trigger a message that will appear in the typical "Drupal Message Area".

Drupal messages work with my theme, but I am not sure how to trigger them without a custom module. However, I am not sure how to link a custom module to a link click!

I really just want to set this message when they click the link.

Another possibility I'm thinking of, is it loads the page, with a line to trigger a javascript overlay window. However, that doesn't use the Drupal message area (which I use all over the site) and may break for some computers, so I'd rather not go that route. I only mention it because I know it is possible.

Comments

VanD’s picture

Could you add a block that people see when the click the link and arrive on the new page?

Does the Notifications module do what you want?

- Craig Vanderlinden @cvanderlinden

streever’s picture

It looks like Notifications is a BIG piece that does a lot--but not necessarily what I'm looking for (forgive me if I missed a feature)--it seems to send messages outside of the site, which isn't what I want.

My hope is that I can just trigger a message on the page they arrive on. The message only applies for people who come via a certain link, so I can't use a block and show it to everyone. I really just want to target those people who click that one link. (there are many ways to get to the page, and the message only applies to people who come a certain way)

I think there is probably some way to set a "status" message in Drupal, which would accomplish this, when people click a link--much like "?destination=page" can be added to any link, I am sure there is a way to set (for example) "?status=message to display"

Does that make sense?

I provide free Drupal support on Thursdays: booking calendar coming soon.

VanD’s picture

Ok, well you can make the block and have PHP code in it something from the URL

If the link they click on is: http://drupal.org/node/111?status=true
If normal visitors want to reach the same node the link can be: http://drupal.org/node/111

if (isset($_GET['status'])) {
     $status = $_GET['status'];
     if ($status == true) {
          echo '<div class="messages">message here</div>';
     }
}

Or something like that.

- Craig Vanderlinden @cvanderlinden

streever’s picture

Oh man, that is perfect. You are the hero of everything. Thank you!

I provide free Drupal support on Thursdays: booking calendar coming soon.

streever’s picture

Sorry, conceptually, it is perfect,but I'm finding it not working! Let me run my code by you and see what I'm missing if you don't mind:

I have a link which sends people to site.com/page?status=true

I have a code in a block which is on that page, which says,

<?php
if (isset($_GET['status'])) {
     $status = $_GET['status'];
     if ($status == true) {
          echo '<div class="messages status">My message</div>';
     }
}
?>

Nothing is appearing, so I'm not sure what I'm doing wrong--is there anything incorrect in that code? It looks right to me and I am seeing no errors, so I assume it is executing.

I added a

It works

line AFTER the closing PHP tag, and sure enough, that appears when I go to the page (using the url?status=true and without), but the actual message does not appear. Thanks in advance.

I provide free Drupal support on Thursdays: booking calendar coming soon.

streever’s picture

WOO! Got it!

A kindly drupal IRC user pointed me in the right direction.

Here is the code:

<?php
// drupal_set_message('GET:<br/><pre>' . print_r($_GET, TRUE) . '</pre>');
if (isset($_GET['status'])) {
  $status = $_GET['status'];
    if ($status == TRUE) {
      drupal_set_message(t("You can add any product from the store to your registry by clicking the Add to Registry button on the product's page."));
   }
}
?>

I provide free Drupal support on Thursdays: booking calendar coming soon.

VanD’s picture

Well done!
Glad it all worked out!

- Craig Vanderlinden @cvanderlinden