2

I'm using Drupal 7 and the Drupal Commerce module. I'm now able to capture an argument passed by URL using Rules (thanks to this helpful thread). However, I'd now like to be able to redirect the user to one page if the argument equals one thing and send them to a different page if it equals ANYTHING else. Anyone know how to do that?

I tried using 'Page Redirect' as an action in Rules, after the action of capturing the argument in the URL (Action > Provide URL argument value), but there's no option in the Page Redirect action to send users somewhere based on the argument value.

So for example, I have users coming to the site with urls like so:

membership-renewal/?ID=promo1

Currently Rules is recognizing that they are using that URL and it's reading 'promo1' value using [ID:value] replacement pattern...I can print it out to the screen so I know it's reading it.

But I don't know how to then use that value to inform a page redirect for example.

Anyone know?

2 Answers 2

2

Well, if you're planning on doing it solely via rules, you can create a new rule for each if in your logic and then just set them to be actions one after the other. Something like this:

Action:
  RULE: 
    IF: <condition>
    REDIRECT: <here>
  RULE: 
    IF: <condition>
    REDIRECT: <here>
  RULE: 
    IF: <condition>
    REDIRECT: <here>

This would effectively work like an if-elseif-else statement (assuming that the redirection is using drupal_goto().

But really, this sounds like a job for a custom action that takes the parameters and includes your own custom logic. It'd probably be a lot cleaner in the long-run.

0
1

To make the value of the URL argument available as new variable to Rules, you can use the Rules URL Argument module. Here is a quote about it (from its project page):

... provides two rules conditions based on URL arguments:

  • check if a URL argument is present.
  • compare the value of an URL argument.

It also provides an action that makes the value of an URL argument available as new variable to Rules.

The newly provided Rules actions and conditions can be found under the "URL Argument" conditions and actions groups in the rule configuration interface.

For an example of how to use it, refer to Comment # 3 in issue # 1686360 which is about "Pass an amount to the url, ie; site/content/node-title?amount=10 or /node-title?=amount:10". Here is the relevant part of it:

  • add a "Check if URL argument exist" condition to your rule and set the "ARGUMENT" value to "amount".
  • add "Provide URL argument value" action to the rule and set "URL ARGUMENT NAME" value to "amount" and in the "Provided variables" section "ARGUMENT FROM URL - Variable name" to e.g. "amount_from_url".

You will now be able to use the amount value as a variable "amount-from-url" for other actions in this rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.