2

I have a select list which contains A and B. If users choose A, then (after submitting the node) the users are redirect to URL A; if users select, they are redirected to URL B. I'm using Rules and adding conditions to try this but no avail.

Maybe I'm wrong in choosing the conditions because I'm so confused right now and there's no documentation for this.

I've considered to use the Conditional Rules module, but since this project not covered by Drupal, I'm hesitating to use it.

2

Solution for option A:

Below is a sample of a rule (in Rules export format) that should allow you to specify a Rules Condition related to a specific value selected via a selection list (and when a new node is created):

{ "rules_new_node_with_special_optionlist_value_a" : {
    "LABEL" : "New node with special optionlist value A",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } },
      { "data_is" : { "data" : [ "node:field-optionlist" ], "value" : "A" } }
    ],
    "DO" : [
      { "drupal_message" : { "message" : "A new node got created with option list value = Advanced" } }
    ]
  }
}

Some more details to further explain the above above sample:

  • The Rules event I'm using is "After saving new content" (replace this event by whatever fits your case).
  • In my case I have a selection list field with machine name field_optionlist.
  • This field actually has 2 possible values, like so:
    • A (=Advanced).
    • B (=Basic).
  • As a sample, I decided to use as condition "The selected value must be Advanced".
  • If that value is selected, then (as Rules Action), a message is shown like A new node got created with option list value = Advanced. Feel free to change that to whatever Rules action, this is how I often "unit test" new rules I write. In your case you want to make it a redirect to your URL A.

The "clue" to make this rule work is the condition Entity has field. That's also what is mentioned in the Rules UI when you're adding a "data comparison" condition: somewhere it says "The data selector helps you drill down into the data available to Rules. To make entity fields appear in the data selector, you may have to use the condition 'entity has field' (or 'content is of type')".

Note that I've not added a Rules Condition here about selected content types, that's probably an extra condition you might want to add also. But if the selection list field is only used for the content types you're interested in, then the Entity has field condition should be sufficient already.

Solution for option B:

Clone the rule you created for option A into a similar rule, this time to check for the value of "B", and to perform a Rules Action to redirect to your URL B.

With those 2 rules in place, your disered logic is implemented, and you don't need the "Conditional Rules" module either.

  • Hi @Pierre.Vriens Thanks a lot for your suggestion, I've tried both of your options and it's works well. This helps me a lot and i really appreciated it :) Thank you.. – uchuneno Jun 12 '17 at 8:00
  • @uchuneno merci for your feedback (and accept/upvote)! I was pretty sure that this would do the trick, but of course a confirmation like yours is the best proof of it ... Next question? – Pierre.Vriens Jun 12 '17 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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