I have created data verification rule for a non required field. If the user enters a value that is above a certain threshold I want the user to be shown a message and the node NOT to be saved. I can't quite figure out how to get that functionality. Here's how I have my rule currently set up. The redirect and the message works, but I always get a "content has been updated" message as well.

    Event:

Before Saving Content

    Conditions:

Content is of type: xxx
Data comparison

    Actions:

Page Redirect
Show a message on the site

Comments

emergencyofstate’s picture

Component: Rules Core » Rules Engine

I'm still stuck with this. My rule works, but the node is always updated with the information anyway. Help please!

v-a-1’s picture

I too am looking for similar functionality.
I need to "not save" the content and issue a system message saying why the content cannot be saved.

v-a-1’s picture

I figured it out. heres how:

Create rule of type "content is going to be saved"

Add condition "if content type is xxx"
And whatever other condition you require to return true or false.

Add action "system page redirect" and set configuration to redirect to the same page.
Set configuration of above action to "immediately issue redirect".
This will stop the process of node creation in its tracks and send the user back to the node creation page.

to issue an error notice to the user.
You can do this by adding a "set configurable system message" action BEFORE the page redirect action.

Hope this helps someone else.

Itangalo’s picture

Status: Active » Closed (won't fix)

This really seems like an issue that shouldn't be solved with Rules. (At least as the module works right now.)

If you want to prevent users from entering certain combinations of values in a form, it makes much more sense to have a custom validation function. This *might* be possible to do with Rules Forms Support in D6, but in D7 it would require some custom coding. (There might be some modules allowing you to build custom validators, but I don't know them.)

Also: If you just want to prevent values above a certain threshold, you could use the "maximum" settings available for number fields.

Marking this as "won't fix". Sorry.

estebant’s picture

Version: 7.x-2.0-beta1 » 6.x-1.4
Status: Closed (won't fix) » Needs review

Hi,
@voodoo.child, for me your solution works except in one detail: all the data introduced by the user before trying to save the node dissapears, so they would have to introduce it all again :(

@Itangalo, how could I implement a custom validation function for this purpose? Any tip? I am not an expert yet with hooks, etc.

Thank you.

estebant’s picture

Status: Needs review » Closed (fixed)

I already found the solution :)
http://groups.drupal.org/node/25403

Itangalo’s picture

@estebant: I was thinking more of writing a custom function in PHP, but if you found a way to do this with Rules that is just fine. Great!

v-a-1’s picture

@estebant: great. thanks for updating with the rules validation option.

laboratory.mike’s picture

Component: Rules Engine » Rules Core

While this may not be the best or most efficient way, you could always include an action to delete the node immediately after it was created, and redirect the user back to the node creation page. I am doing that right now for a workaround to #1918216: Resource Conflicts are not detected in certain cases, though it would probably be better if I learned some PHP and wrote a validation function.

Solariss’s picture

@v-a-1
Your recipe is for D6, but I have no Ideas how to interrupt saving a node in D7 by Rules.

giorgio79’s picture

Version: 6.x-1.4 » 8.x-3.x-dev
Issue summary: View changes
giorgio79’s picture

Version: 8.x-3.x-dev » 6.x-1.4

Changed version by accident.

fnapo’s picture

Working for me using "Before Saving Content" and a PHP custom code with drupal_goto() function inside (D7)