1

I need this in Rules:

When a node is being created (before the node is saved), and certain conditions are true, the user can't create the node, and an error message appears instead.

I have a rule that is working, and the error message is displaying. But the node is still created.

Is there a way to prevent node creation in rules?

Note: I'm using Drupal 7. I selected the Action "Show error message" directly on rules.

2
  • Please provide which version of Drupal you're using. Also are you showing error messages using drupal_set_message or form_set_error?
    – Yogesh
    Nov 21 '16 at 11:01
  • I'm using Drupal 7. I selected the Action "Show error message" directly on rules...
    – Drii7
    Nov 21 '16 at 11:48
1

Out-of-the Rules module-box, I think there is no solution to "prevent node creation in rules?" (as in your question). However, without using custom code and custom PHP in your Rules conditions or actions and without deleting the node after it got created, you may get it to work if you also use the Rules Forms Support module.

More details about Rules Forms Support (from its project page):

Rules Forms Support provides a Rules based method for controlling forms and their elements. The module can be used to alter any form provided by Drupal core or contributed modules. Change element titles, descriptions, weights, and more, or validate form data and set form errors. Rules forms saves time and cost by affording site builders the ability to monitor and alter forms without the need to implement a custom module.

For help getting started with Rules Forms Support, please see the module documentation.

Features

  • Activate events for form creation, validation, and submission on a form-by-form basis.
  • Target individual form elements or the entire form in conditions and actions.
  • Manipulate the attributes of a form element like title, description, weight, and more.
  • Validate the values of form elements during form validation.
  • Set form errors when rule-based validation fails.
  • Redirect users to a different page upon viewing or submitting a form.
  • Examine the attributes of elements in active forms with the element inspection tool.

Especially the "Set form errors when rule-based validation fails" should help to address your question.

More details about how to use this module can be found in the community documentation "Altering & validating forms".

0

I solved this by using the drupal_goto function.

0

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.