HowTo: Configuring Triggers and Actions in Drupal 6
Drupal 6 offers built-in actions that can be performed whenever something happens on your site. Typically, you want to use this to get an alert when someone publishes content on the site, or a new user signs up.
You might even want to mimic WordPress and get an email alert every time someone leaves a comment on the site. I’m going to show you how to set this up for your site.
Defining Triggers and Actions
First, let’s take a look at what triggers and actions actually are. A trigger is an event which will happen on your site. Triggers that I can see on my site are Comments, Content, Cron, Taxonomy and Users.
If you look at the available triggers for Comments, you’ll see various trigger types. The one we’re interested in is “After saving a new comment”.
Before you can activate a trigger, you need to specify an Action. This is the action you want to happen each time a trigger is ..er.. triggered. You can do a number of things with actions, such as redirect users to a URL or give them a message on the page. However, we’re mostly interested in the Send Email action.
Step By Step Instructions
OK. So let’s set up a simple action and trigger combo to send us an email each time a comment is left on our Drupal site.
- Before you start: Make sure you’ve got the trigger module activated. Browse to Administer -> Site Building -> Modules and check that Trigger is enabled. If not, switch it on, obviously!
- Now, let’s set up our action – browse to Administer -> Site Configuration -> Actions. Drop down the Make a new advanced action box and select Send e-mail. Click Create.
- Set up your alert email with an easy to recognise Description and Subject – I used “New Comment on [Sitename]” for mine. Enter the email address of the person who’s supposed to receive the alert (probably you) and then enter a short message – you should see some variables underneath the text field showing variables you can use.
- Save your changes et voila, your action is configured. Now to attach it to a trigger…
- Browse to the Trigger page in Adminster -> Site Building -> Triggers. Click the Comments tab and drop down the list underneath After saving a new comment. You should see your email in the list – select it and click Assign.
- Job done – your action has been configured.
Don’t Forget To Test
You didn’t think we were finished yet, did you? Now you need to test that the triggers are working correctly.
Just to approach this as a regular site visitor, log out of your Drupal site. Or, if you’re smart like me, just fire up another web browser where you’re not logged on to the site (that way, you can still use the admin part of Drupal in your main browser and test the average user experience in the other).
Simply visit any blog post on the site (or any node that allows comments) and leave a comment on that post. Now, head on over to your email inbox and wait for that alert to arrive. Mine arrived in just a couple of minutes.