If the Rules action "Set form error" is given the ID of a CCK field (i.e. something like "group_somegroup[field_somefield][0]"), the form error message appears correctly, but the field is not highlighted in red.
The bug appears to be in rules_forms_action_set_error(). The implementation assumes that the field name to pass to form_set_error() is simply the result of imploding the '#parents' array, but this doesn't work for CCK fields because they have nested form elements. For example, the proper name to pass form_set_error() for a CCK text field would be something like "group_somegroup[field_somefield][0][value".
CCK gets around this problem by adding an extra "_error_element" array to the element's form state. The value of the '#value' key in that array provides the full field name to pass to form_set_error.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 758000-cck-element-ids.patch | 1.51 KB | klausi |
| #4 | rules_forms_cck_form_set_error.patch | 697 bytes | guypaddock |
| #2 | rules_forms_cck_form_set_error.patch | 673 bytes | guypaddock |
Comments
Comment #1
guypaddock commentedA temporary workaround to the issue is to add "[value]" to the end of the form ID provided to the "Set form error" action (so "group_somegroup[field_somefield][0]" becomes "group_somegroup[field_somefield][0][value]").
Comment #2
guypaddock commentedThe attached patch appears to correct this issue.
Comment #4
guypaddock commentedRe-submit with patch created from the root folder of the rules module.
Comment #5
klausiHm, I don't think this is the right way to go. The problem is that the form element IDs are not displayed correctly in the display form element IDs mode. Here is a patch that moves the addition of these IDs to the after build handler, where the CCK fieldgroup stuff is already done. Then we have the correct IDs on the form, with [value] in the case of CCK.
Inspired by fago @drupalcon sf
Comment #6
robby.smith commentedsubscribing
Comment #7
Bilmar commentedHello,
The patch at #5 applied smoothly and I made a screencast of the difference in element ID info on the node edit page before and after applying the patch (very different!) Are all the element id info shown in the screencast suppose to be showing?
http://www.screencast.com/users/trupal218/folders/Jing/media/e78d6c62-e3...
Screencast includes:
- cck text field select list
- imagefield cck field
- cck text field checkboxes
- cck content taxonomy field checkboxes
I tested by creating a rule.
Triggered event: Profile node is being validated
Condition: Form element has value
Action: Set form error
I used field_example[value] as the element id as indicated on the node edit page after patch applied. Saving the node with value selected in condition sets the form error with message.
Without the element ids that show due to the patch, I wouldn't have known how to make this rule work. I hope this is something that can get committed after more review to make it easier for those using rules forms. Thanks so much!
Regards
Comment #8
fago#5 makes a lot of sense to me as it ensures that every element available during validate+submit is shown - this is as during the form processing form elements might be expanded to multiple elements. Validate+submit always run "after-build" however the "form is being built" event not - what might generate confusion as those *new* values are probably not available there.
Comment #9
fathershawnThis may explain my lack of form error, added into the comments of #576718: 'Form element has value' fails to match CCK field on build form. The field I'm testing is in a CCK field in a fieldgroup and the rule condition always returns false. I'll try adjusting the id.
Comment #10
fathershawnNope - didn't fix my error.
Changed id from field_workflow to group_status[field_workflow][0][value]
Still doesn't evalutate to true when it should.
Comment #11
YK85 commentedsubscribing
Comment #12
robby.smith commented#5 helped me after many hours of confusion and hair pulling
+1 for adding to help admins using this
Comment #13
klausiCommitted #5 for now, not ideal but at least all element IDs are visible now.
Comment #14
nodecode commentedI have posted a support request question that was raised a result of this thread. It has to do with Element IDs and why they might not be present during the "form is being built" event.
my support request: http://drupal.org/node/893738
Any input is greatly appreciated.