Hello,
I am attempting to author a rule that is triggered when two fields are left blank on a node, posting a form error and preventing submission (the idea is that the author needs to select one or both, but can't leave both blank). The conditions for my rule are operating as expected (e.g. I can say 'dsm("works");' in the actions section and I get a response when expected). I have tried using all triggers under the node section of the triggers to no avail.
The rule is currently set up as:
- Events
- Before saving content
- Conditions
- Content is of type (Parameter: Content: [node], Content types: File)
- User has role(s) (Parameter: User: [node:author], Roles: employee, project manager,..., Match roles: any)
- Data value is empty (Parameter: Data to check: [node:group-audience])
- AND
- Data value is empty (Parameter: Data to check: [node:field-file-company])
- Actions
- Execute custom PHP code (Parameter: PHP code: form_set_error('field_file_company', t('It is required that you select either company level access, group level access, or both.'));
So, I get a form error, but it appears on the node being edited's display page *above* a message stating "*node name* has been updated.".
Any ideas why my form_set_error isn't preventing the form from submitting? I know I have the field names right. Thanks,
Rich
Comments
Comment #1
jordojuice commentedJust speculation (because i havent looked at exactly how that action is executed) but maybe it's because the form_set_error() call is not being executed from the validation handler? If that is the case, we just ported Rules forms support to D7, and that module can certainly check the validate fields and call form_set_error() from the validation handler itself. I'd recommend the dev version if you use it as it has some useful updates.
Comment #2
tr commentedIf you continue to have a problem with this in the current version of Rules please open a new issue.