I'm trying to validate field's content with Rules Forms.

Drupal built-in validation lets me validate only against predefined static values, whereas Rules provides a numeric comparison.

The problem is that Rules Forms seems not to make use of «content» argument in triggered rules.

When creating a triggered rule based on a Rules Forms event, i can't return a field's value because this type of condition is unavailable. No actions for fields either.

Okay, i can manually add the Content argument in Rule Sets and get access to field-based actions and conditions. But i still can't make use of it! To execute the ruleset, i have to call it from a triggered action. And in triggered rules based on a Rules Forms event there are no ruleset-based actions! Why? Seems it's because Rules Forms does not implement «content» argument.

Comments

klausi’s picture

Category: bug » support

Yes, a Rules Forms event does not provide a content argument, but a form and form_state argument. Therefore you cannot make use of rule sets that expect a content variable as argument. You can use the "load content by ID" action to make a content variable available.

lolmaus’s picture

Status: Active » Closed (fixed)

Yay thx! Gonna try that.

lolmaus’s picture

Status: Closed (fixed) » Active

But how do i provide the id for "load content by ID"? Rules Forms won't provide a nid token. :(

klausi’s picture

very hackish workaround: use the following php code in the content ID field of the load content by ID action:
echo $form['nid']['#value'];

dutch45612’s picture

You need FIRST to activate the EVENT on that very form you are trying to trigger the action from --> In your Rules configuration --> Events form --> activate the two option that are here and save --> Now go back to your create form of that node type as if you were a user going to fill that form (you need to go logged as Admin of course )--> You should see now above a link to "activate events on this form" --> Click on it --> Save -- Et voia .... Now if you want to remove event listening on that form you go to form event setting in Rules and delete it from there ...

Hope that helps .

iamdan’s picture

I'm hoping I can jump in and get some help for a non-programmer type who is cobbling together some Drupal sites for school. I'm trying to add some checkboxes on a form and then use a rule to send e-mail to different sets of users. I have set up the form with a field called 'field_promote' with these allowed values

1|add to events page
2|send e-mail to faculty
3|send e-mail to graduate students
4|send e-mail to undergraduate students

I then went to the form and did the activate event step.

Now on the rule set up I made condition to check for the checkboxes. I have the form and form state menus available and then for field id I put 'field_promote'. I'm thinking that if I want to check for the faculty box, for instance, in the value text box below I would put '2'

I know that I'm unclear about exactly how to identify the form field. I have tried 'edit-field-promote-value-2' which is what shows up in the code. I have tried 'field_promote[value][2]'.

So, my apologies for the level of this query and its possible misplacement here and my main questions:

Do I need to worry about the content argument messages/setup that comes up when creating the rule--is this preventing it from recognizing my checkbox?

Of, if I'm on the right track, what am I doing wrong with my field id and value stuff on the form and in the rule. I'm aware that I may just not know how to get those linked up just right, though I have looked around.

Thanks for any insights.

joetsuihk’s picture

i am still confusing after reading the above.

i did #5, which created a trigger when my form validate, but i cannot put a condition to validate my field

and i have no idea what #1 and #4 is doing... i can put php code to the text field of "load content by id"?

is rules form aim to provide a validation framework? or we just mis-used it?

joetsuihk’s picture

Priority: Normal » Critical

No one?
this is critical as validation api module stop developing and claim this module can do the same thing.
but we still miss lots of features here. At this moment, this "validation" barely usable.

1. token do not provide form element for validation
2. we do not have reg exp check in form comparison

lolmaus’s picture

Do they ever tried that themselves? Seems to be only a theoretical suggestion, not a real-life example. :(

apratt’s picture

iamdan - did you get this sorted out? I'm trying to do a similar thing but stumbling in a slightly different spot. I can't see how to have different emails sent when the condition is met.

mitchell’s picture

Title: Rules Forms: can't validate field's content (lack of content argument). » Field validation lacks a content argument
Category: support » bug
fago’s picture

Category: bug » feature

Maybe it would make sense to provide special support for node forms, thus having a special event providing the variable? For d7 it probably would make sense to do that for "entity forms" in general.

YK85’s picture

subscribing

thekevinday’s picture

subscribe

TY2U’s picture

Update! I found an easier and better way to do this. Create one trigger with Event of "After saving new content". Add a condition of "Content has type" and select the content type (I selected Project release). Then all that is left is to add a role for "Send a mail to all users of a role". A whole lot of work and messing around to figure such a simple thing out.

I think I figured out what might be a missing piece here so I may as well tell you all about it in great detail.

I just got introduced to this Rules module because I wanted to send members of a specific role an email when a new content item of a specific type is added. In this case I wanted to send members in the "Paying Customer" role a notice of an update when a new project_release is created.

So I went to figuring out the Rules module and it is very confusing at first but once I figured it out it isn't so bad.

Here are the steps I followed:

1. Go to admin/rules/forms. Make sure "Enable event activation messages on forms" is checked. You can also check "Display form element IDs" and remember to click "SAVE SETTINGS".

2. Go to the form you want the event to fire on when you submit it as if you were going to submit the new content or whatever. At the top of the page you should see "Activate events for the_form_name". Click the_form_name which will be whatever the form is named you want to use. This will activate the event for this form. You have to be logged in as admin for this. This is also explained in Post #5 above.

3. Add a new rule set. admin/rules/rule_sets/add.

In "Label" you can name it whatever you want, I named mine New Release.
In "Machine readable name" I entered new_release.
In "Categories" I entered new release.
For "Arguments" below in the "Data type" column select "Content" from the drop down.
Click "Save".

4. Add a new rule. admin/rules/trigger/add. This is under Triggered rules.

Enter a "Label". I entered New release.
For "Event" I selected an option under "Rules Forms" called "Project release node form is submitted". I believe this matches the name of the form you used in step 2.
For Categories I entered new release.
Click "SAVE CHANGES".

5. You should now be taken to a page titled "Editing rule New release" where New release will be whatever you labeled your rule. Click "Add an action" and select "Load content by id" which is under "Node". Click "Next".

6. You should now be taken to a page titled "Editing action Load content by id". All you have to do on this page is paste in the token replacement pattern for the node id [node_loaded:nid] and click "Save".
If you tried adding a condition now you won't be able to select the "Content is new" condition so on to the next step.

7. Now add a new rule with the same settings as you did in step 4. You can Label it something different so you can tell them apart if you wish. I made mine New Release2. I also changed the "Weight" to 1. Click "SAVE CHANGES".

8. Now you are taken back to the same screen as in step 5. This time you can click "Add a condition". Select "Content is new" in the drop down and click "Next".

9. This will take you to another screen saying "Editing condition Content is new". If you want to check if content is new simply click "Save".

10. Now we still have a problem that if you do anything with the node such as edit or delete it users will still get an email. So we have to add some more conditions to this 2nd rule. So click "Add a condition" again and this time select "Form element has value" under "Rules Forms". Click "Next"

11. Put a checkmark in the Negate checkbox. For the "Form element ID" enter "buttons[delete]" without the quotes. Then in Value(s) enter "Delete" without the quotes. This will cause Rules to only fire if there is no delete button. Click "Save".

12. Click "Add an action". Select the action you want. I selected "Send a mail to all users of a role". Click "Next".

13. Now you can check off the role(s) you want to send mail to and enter the email you want to send below. You can even use Token replacement patterns if you have the Token modules installed.

And finally... that's that! Now whenever you submit the form and content item is new it will send email to members in the roles you selected.

Good luck!

Ryan

lolmaus’s picture

Hey thanks TY2U.

I believe this should be documented somewhere.

mitchell’s picture

Title: Field validation lacks a content argument » How to: Provide field validation a content argument for forms support
Component: Forms Support » Documentation
Category: feature » task
Priority: Critical » Normal

Please compile this information into a documentation page.

Encarte’s picture

Title: How to: Provide field validation a content argument for forms support » Make it possible to add a content argument to a form rule
Component: Documentation » Forms Support
Category: task » feature

#15 doesn't work because the token [node_loaded:nid] (see step 6) isn't available. Why would it be? You can't have a variable available in the very action that is supposed to create it.

Also #5 is not a resolution to this problem, it is just a how to enable forms for a content type.

#4 results but, like Klausi said, it's really hackish.

So I think this is still a feature request: make it possible to add a content argument to a form rule. It could be done if there was a way to pass the nid to the Load content by id action. Or if there was a Load current content action. Don't know if any of this would work with new contents but doing it with existing contents would be very useful.

kenorb’s picture

TR’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Active » Needs work

Drupal 6 end-of-life was more than two years ago - there will be no new feature in D6 Rules, and D6 Rules is no longer supported.

That said, this could go into Rules for D7 or D8 if someone is willing to contribute code or fund the development of this feature.

TR’s picture

Project: Rules » Rules Forms Support
Component: Forms Support » Code