No way to flush form errors during iterative programatic form submission

andremolnar - October 1, 2007 - 20:11
Project:Drupal
Version:6.x-dev
Component:forms system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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

AttachmentSizeStatusTest resultOperations
form.inc__5.patch726 bytesIgnoredNoneNone

#1

andremolnar - October 3, 2007 - 16:29
Status:active» needs review

there's a patch - changing status to reflect this

#2

TheMystic - November 27, 2007 - 21:38

Instead of resetting $form to NULL, shouldn't it be reset to an empty array? Corrected patch attached.

AttachmentSizeStatusTest resultOperations
form.inc_.patch729 bytesIgnoredNoneNone

#3

R.Muilwijk - June 25, 2008 - 22:36

I would like this to get in. Runned all tests without problems. The patch was not made on the right way though. Right patch supplied.

AttachmentSizeStatusTest resultOperations
form_reset_errors.patch769 bytesIgnoredNoneNone

#4

moshe weitzman - June 27, 2008 - 01:46
Status:needs review» needs work

I 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.

#5

R.Muilwijk - June 27, 2008 - 06:33
Status:needs work» reviewed & tested by the community

Reworked $flush to $reset. As moshe suggested patch to RTBC

AttachmentSizeStatusTest resultOperations
form_reset_errors.patch769 bytesIgnoredNoneNone

#6

chx - June 27, 2008 - 09:14
Status:reviewed & tested by the community» needs work

Sorry, not yet. This needs doxygen.

#7

R.Muilwijk - June 27, 2008 - 15:00
Status:needs work» needs review

With doxygen :d

AttachmentSizeStatusTest resultOperations
form_reset_errors.patch968 bytesIgnoredNoneNone

#8

moshe weitzman - June 27, 2008 - 20:50
Status:needs review» reviewed & tested by the community

well done. thanks.

#9

chx - June 28, 2008 - 05:26

I concur, this is fine.

#11

KarenS - July 3, 2008 - 01:10

Moshe, 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.

#12

catch - August 14, 2008 - 16:46

Still applies.

#13

webchick - September 19, 2008 - 02:38
Version:7.x-dev» 6.x-dev

Seems 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.

#14

Gábor Hojtsy - September 23, 2008 - 10:05
Status:reviewed & tested by the community» fixed

We'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.

#15

Anonymous (not verified) - October 7, 2008 - 10:12
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#16

vivianspencer - December 6, 2009 - 09:10

Is this fixed for 5.x?

 
 

Drupal is a registered trademark of Dries Buytaert.