2

I have created a Rule with the Rules module to validate the form on submission.

I try to compare the values of two fields to ensure one not higher than the other. But I couldn't find the appropriate Rules Actions to stop the form submission and prompted an error message.

Please advise.

Event: After saving new content of type Article

Condition: Data comparison Parameter: Data to compare: [node:field-price-A], Operator: is greater than, Data value: [node:field-price-B]

Actions: ??

1
  • 2
    Have you tried with the Event: BEFORE saving...?
    – user35009
    Aug 11, 2014 at 12:00

2 Answers 2

3

It sounds like you don't have the supporting module Rules Forms: https://www.drupal.org/project/rules_forms

This module adds form validation for existing (core) forms and custom forms from contrib modules.

The documentation states that Rules Forms can:

Validate the values of form elements during form validation. Set form errors when rule-based validation fails.

1

Have a look at the Rules Forms Support module. More details about it (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".

6
  • Hi , can anybody tell me what action i need to add for set form error for particular field? I'm not finding the my required field in Data selector though i have added that field in Condition under 'Entity has field'.
    – rks
    Jul 27, 2016 at 7:52
  • @rks I'm about sure it is Rules Action "Set an error on the form", as shown in the code around here ... If you want, why not post a new question about it (eventually with a reference to this question here). If you do, let me know via an extra comment (ping) around here, ok? Jul 27, 2016 at 8:24
  • here is the link for my question. I have added the screenshot of my events and conditions. Please let me know Which data selector i need to select for "Set an error on the form" action, since i'm not finding my required fields in the data selector
    – rks
    Jul 27, 2016 at 9:10
  • Is there a similar module for Drupal 8 ? Jun 6, 2017 at 15:56

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.