[development] Unsetting form values on validate
Michael Prasuhn
mike at mikeyp.net
Tue Oct 21 19:45:22 UTC 2008
On Oct 20, 2008, at 9:29 PM, Andrew Berry wrote:
> I'm curious as to why CCK with a bunch of optional fields doesn't
> work for this. Could you not do a bit of custom PHP to validate
> fields within CCK?
I am using CCK fields. This application requires the use of
conditionally required/available fields. In order to make this work
reliably, I am discarding data submitted for unavailable fields on
validation, instead of trying to validate a field that doesn't
correspond to the listing type.
On Oct 20, 2008, at 11:21 PM, Derek Wright wrote:
> That's because of this critical bug in the D6 API:
>
> http://drupal.org/node/241364
> "hook_validate() doesn't get $form_state passed to it"
>
> Sadly, since that'd be a pretty major API change in a supposedly
> stable release series of core, it's probably not going to be fixed. :
> ( But, it makes hook_nodeapi() quite useless in many cases, and has
> caused (and will continue to cause) all sorts of grief for a variety
> of modules. Tragically, no one noticed until after 6.0 was out.
> The current work-around is to form_alter() and add your own
> #validate handler, which *does* get a copy of $form_state as nature
> intended. Arguably, that's cleaner than using hook_nodeapi() in the
> first place, but then what's the point of having
> hook_nodeapi('validate') at all?
I suppose whether or not $form_state should be in
hook_nodeapi('validate') is debatable. I can see the utility of it
here, yet I can see the argument that it is a misuse of hook_nodeapi,
as it really has nothing to do with the node object itself, but the
form. Thanks for the suggestion with the custom validation function.
On Oct 20, 2008, at 11:13 PM, Adrian Rossouw wrote:
> Anyway, to answer the question, i know in d4.7/d5 you could do
> form_set_value('field][field', 'value') to set fields
> in the validate functions, i don't know if in D6 you can just modify
> the $form_state.
This would be ideal, however in D6 the $form_state is a required
parameter of form_set_value() and the absence of $form_state in
hook_nodeapi('validate') is the problem I was running into. Derek's
suggestion of adding my own validation with hook_form_alter() makes
the most sense, as it will pass $form_state to my function.
-Mike
__________________
Michael Prasuhn
mike at mikeyp.net
http://mikeyp.net
More information about the development
mailing list