At present validation functions are called in the wrong order. E.g. A password confirm field is checked in the module for password length. The password length check occurs before the check for them being the same, which is built-in.

Another nasty repercussion of this call ordering is when credit card details are validated. I'm currently building a reuseable FAPI type for credit card information. It will have built-in functions to validate the card number and expiry date. Credit card payments are transacted (with the payment gateway) during the validation step, so if they fail the form doesn't reach the submit state. With the current ordering, and the proper implementation using #validate on the credit card type, the payment transaction is executed before validation of the card number and expiry date.

A similar problem exists for date type validation.

I realise fixing this bug will require some pretty heavy testing. It is required though because the benefits of using built-in (and reuseable) validation are unavailable with the current implementation.

Having looked through form.inc to find a possible solution, it may be possible to utilize the $form_id parameter to _form_validate() to work out when run the validation after the children have been validated. The only problem I can see occurring is when there are forms within the children where $form_id is not null.

At this stage, i'd like to hear from others about their thoughts on the call ordering and from the FAPI developers on how hard it would be to do a fix.

--
Sammy Spets
Synerger Pty Ltd
http://www.synerger.com

CommentFileSizeAuthor
#1 validate.patch759 byteschx

Comments

chx’s picture

Status: Active » Needs review
StatusFileSize
new759 bytes
sammys’s picture

This patch may solve the problem. I don't know whether all forms will still work though. If you FAPI people say it will then that's the patch I need.

moshe weitzman’s picture

somwhat related - would it help for submit and validate handlers to have weights instead of order in their arrays? thats seems more consistent with form_render() and menu system, and so on.

sammys’s picture

It is somewhat related yes. This is another enhancement i've been contemplating. User supplied #validates are given precedence over those set by hook_element()/element expansion functions. This is bad.

dries’s picture

I committed chx's patch to CVS HEAD. It needs more testing before this can be backported to DRUPAL-4-7.

killes@www.drop.org’s picture

yes, I agree. Somebody make some tests, please.

killes@www.drop.org’s picture

Status: Needs review » Fixed

We didn't get any tests (besides the ones I did myself) but no bug reports on HEAD either, so I backported it.

Anonymous’s picture

Status: Fixed » Closed (fixed)