Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
emergencyofstate CreditAttribution: emergencyofstate commentedI'm still stuck with this. My rule works, but the node is always updated with the information anyway. Help please!
Comment #2
v-a-1 CreditAttribution: v-a-1 commentedI 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.
Comment #3
v-a-1 CreditAttribution: v-a-1 commentedI 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.
Comment #4
Itangalo CreditAttribution: Itangalo commentedThis 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.
Comment #5
estebant CreditAttribution: estebant commentedHi,
@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.
Comment #6
estebant CreditAttribution: estebant commentedI already found the solution :)
http://groups.drupal.org/node/25403
Comment #7
Itangalo CreditAttribution: Itangalo commented@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!
Comment #8
v-a-1 CreditAttribution: v-a-1 commented@estebant: great. thanks for updating with the rules validation option.
Comment #9
laboratory.mikeWhile 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.
Comment #10
Solariss CreditAttribution: Solariss commented@v-a-1
Your recipe is for D6, but I have no Ideas how to interrupt saving a node in D7 by Rules.
Comment #11
giorgio79 CreditAttribution: giorgio79 commentedrelated #1780526: Support Entity Validation in D8
Comment #12
giorgio79 CreditAttribution: giorgio79 commentedChanged version by accident.
Comment #13
fnapo CreditAttribution: fnapo commentedWorking for me using "Before Saving Content" and a PHP custom code with drupal_goto() function inside (D7)