Currently form_set_error holds errors in a static variable. There is no way to flush this variable.
Use case: You are writing a script to programatically submit the same form iteratively using drupal_execute with different values in each iteration.
Current Problem: If any form sets an error during code execution (in any iteration) - all subsequent form submissions will fail with the same error since the errors are stored in a static variable.
Possible Solution: provide an interface to flush the errors.
Attached is a patch that would do this. It simply adds a param to form_set_error. form_set_error could then be called between iterations to 'flush' or 'reset' the error array.
andre
Comment | File | Size | Author |
---|---|---|---|
#7 | form_reset_errors.patch | 968 bytes | R.Muilwijk |
#5 | form_reset_errors.patch | 769 bytes | R.Muilwijk |
#3 | form_reset_errors.patch | 769 bytes | R.Muilwijk |
#2 | form.inc_.patch | 729 bytes | TheMystic |
form.inc__5.patch | 726 bytes | andremolnar | |
Comments
Comment #1
andremolnar CreditAttribution: andremolnar commentedthere's a patch - changing status to reflect this
Comment #2
TheMystic CreditAttribution: TheMystic commentedInstead of resetting $form to NULL, shouldn't it be reset to an empty array? Corrected patch attached.
Comment #3
R.Muilwijk CreditAttribution: R.Muilwijk commentedI would like this to get in. Runned all tests without problems. The patch was not made on the right way though. Right patch supplied.
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedI believe we typically use $reset instead of $flush (e.g. node_load()). Otherwise, this looks good. Feel free to RTBC it after that change.
This issue is killing mailhandler module as it tries to validate multiple nodes/comment submissions in a single request.
Comment #5
R.Muilwijk CreditAttribution: R.Muilwijk commentedReworked $flush to $reset. As moshe suggested patch to RTBC
Comment #6
chx CreditAttribution: chx commentedSorry, not yet. This needs doxygen.
Comment #7
R.Muilwijk CreditAttribution: R.Muilwijk commentedWith doxygen :d
Comment #8
moshe weitzman CreditAttribution: moshe weitzman commentedwell done. thanks.
Comment #9
chx CreditAttribution: chx commentedI concur, this is fine.
Comment #10
moshe weitzman CreditAttribution: moshe weitzman commentedLets commit. #273570: attachments should (optionally) inherit the exposed filters from parent display and #260934: Static caching: when drupal_execute()ing multiple forms with same $form_id in a page request, only the first one is validated and #272042: There is no way to reset validation errors are all dupes of this issue.
Comment #11
KarenS CreditAttribution: KarenS commentedMoshe, I'm not sure http://drupal.org/node/260934 is a duplicate. That one is a static cache in the validate function. If a form doesn't get past that, it will never even get to this place in the code.
Comment #12
catchStill applies.
Comment #13
webchickSeems sane, and has the thumbs-up from the FAPI maintainer. Committed. Moving to 6.x, since the two referenced bugs were against 6.x modules. I don't know that we can apply it there since it's an API change, but moving it for Gabor nonetheless.
Comment #14
Gábor HojtsyWe've done a similar small API expansion with the XML-RPC error handler on call from Dries, so I see no reason this should not get in. it does not affect the existing code. Committed to 6.x.
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #16
vivianspencer CreditAttribution: vivianspencer commentedIs this fixed for 5.x?
Comment #17
westbywest CreditAttribution: westbywest commentedI can't find this particular issue (#180063) listed as fixed on any recent D6 release. Has it been fixed yet?