I had to play with Rules for forms today so I thought I'd write up the details. Here's an example of a rules setup to handle checking a cck date field when a node is being created.
I have a content type called Offer which has a cck field called offer_date (identified as field_offer_date).
The required behavior is that if the "to" portion of the offer date is in the past - the form validation should fail and an error should be shown.
1) we have to enable form events for the node/add/offer form. Goto admin/rules/form and click "enable event activation messages on forms"
2) Next we activate rules form events for our form. Go to node/add/offer and click on the "Activate events for offer_node_form" link
3) we can now un-check the "enable event activation messages on forms" checkbox if you only have one form you need to work with.
4) Now we create a new triggered rule - admin/rules/trigger/add
5) give the rule a name - like "No offers requiring Time Machines"
6) for the event select "Offer Node Form is Being Validated" then add in categories if you like and click on the "save changes" button.
7) Now we add a condition - select "Rules - Numeric Comparison" and click next
8) In the "Number 1" textbox we type the following:
<?php
echo (strtotime($form_state['values']['field_offer_date'][0]['value2']))
?>
9) choose "less than" as the operation
10) for "Number 2" enter the following :
<?php
echo (time())
?>
The php statement in step 8 takes the entered 'to' date from our date field and converts it into a timestamp - the php in step 10 does the same for the current time - and the comparison checks whether the "to" date is less than the current time. If we wanted to use the "from" date for comparision - just change the last part of the line in step 8 from ['value2'] to ['value'].
11) Almost Done - Now under the "DO" section click on "add an action" and select "Rules Forms - Set a Form Error" and click next
12) Fill out the label by adding in the field element we are setting the error for 'field_offer_date'
13) Under Form Element ID: Type the form element - 'field_offer_date'
14) Fill out the message with something meaningful like: "Hey unless our customers are Captain Kirk - they will never be able to use this offer - please choose an ending date that is in the future"
15) Click save and we're done!
To find out the form element id's you can check the 'display form element id's' checkbox on the rules forms settings page.
Troubleshooting the rule evaluation took me a good couple of hours and I hope this walkthru will save others some of that time.