Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Working on a new field type I've found that for some reason hook_validate is being called twice. It may be deeper than content.module, but I haven't notice validate being called twice in other modules. Maybe a form/#validate issue?
Comment | File | Size | Author |
---|---|---|---|
#2 | validate_one.patch | 710 bytes | chx |
Comments
Comment #1
decafdennis CreditAttribution: decafdennis commentedYes, the validate functions are called by
drupal_get_form
et all, like they should be. The second time, they're called bynode_form_add_preview
.I don't know whether this is a big problem for anyone, I just wanted to mention it and see how it is caused.
Comment #2
chx CreditAttribution: chx commentedThe preview stuff happens before the drupal_validate_form call and is needed. The drupal_validate_form call is just not smart enough to know that it has been called on the same form but that can be fixed...
Comment #3
decafdennis CreditAttribution: decafdennis commentedGood solution, but, wat does the #validated flag in _form_validate (http://drupaldocs.org/api/head/function/_form_validate) do exactly?
Comment #4
chx CreditAttribution: chx commentedthat's form API level checker but if you look at the code flow it's a copy of the form that's changed.
Comment #5
hunmonk CreditAttribution: hunmonk commented+1, code looks good. this should work ok w/ multipage forms, as the current implementation only needs to be validated once.
Comment #6
decafdennis CreditAttribution: decafdennis commentedThe form gets recursed by _form_validate, passing a copy of subelement to that function. What then is the use of #validated? In what situation would
!$elements['#validated']
at the top of _form_validate ever result infalse
?Comment #7
hunmonk CreditAttribution: hunmonk commentedtested the patch using the multipart example module. all validate functionality seems to work fine.
Comment #8
hunmonk CreditAttribution: hunmonk commentednaquah: #validated can be marked for any form element prior to the validation code running. probably not a common use case, but still possible...
Comment #9
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedapplied
Comment #10
chx CreditAttribution: chx commentednaquah, the whole form API is loaded with safety belts. #processed, #after_build_done, #theme_used, #printed just a few comes to my mind. If you are recursing AND such belts add little code, it's better for them to be there. I can rwite you a form array which would recurse on itself using some reference magic. But are you sure you want to have nightmares of that :) ?
Robert, ask nedjo, currently he knows best. Or read the code, that's what I'd do if I'd want to answer :)
Comment #11
decafdennis CreditAttribution: decafdennis commentedchx, thanks for clearifying it... and I have enough nightmares from other things already. Thanks again, this is a good way to learn stuff.
Comment #12
(not verified) CreditAttribution: commented