hook_validate() doesn't get $form_state passed to it

rcourtna - April 1, 2008 - 15:59
Project:Drupal
Version:6.x-dev
Component:forms system
Category:bug report
Priority:critical
Assigned:Unassigned
Status:active
Description

hook_validate() expects 2 args: ($node, &$form)
form_set_value() expects 3: ($form, $value, &$form_state)

As a result, there is no way to pass $form_state to form_set_value() when inside of hook_validate().

Bentley_: ouch. true.
Bentley_: that's a critical bug, file a report.
eaton: Bentley_ just discovered we do not pass in $form_state to hook validate / nodeapi op validate

#1

dww - April 26, 2008 - 19:03

Yup, this is going to be a big problem for trying to port project* to D6.

#2

aclight - April 26, 2008 - 20:17
Version:6.1» 6.x-dev

Indeed, it will be. This is extra confusing because on api.drupal.org (http://api.drupal.org/api/function/hook_validate/6), the notes for hook_validate() state that "The preferred method to change a node's content is to use or hook_nodeapi($op='submit') instead. If it is really necessary to change the node at the validate stage, you can use function form_set_value()." Actually, neither of these will work, at the present. D6 no longer uses the 'submit' op in hook_nodeapi(), and of course you can no longer call form_set_value() unless you can pass in $form_state as a parameter, and that's not possible to do from hook_validate().

#3

dman - April 27, 2008 - 16:17

Yes, this is hurting me today, trying to update image_attach to a usable state.
I need to update a node with the newly-created image info, and the only place that seems to be able to do now it is nodeapi(validate).

form_set_value() cannot work within hook_nodeapi(validate)

Perhaps we can pass the $form_status in that overloaded 4th argument if appropriate?
... as this is pretty broken and pretty critical, it looks like I'll have to find some other, even hackier way to resurrect image_attach on 6. :(

#4

dman - April 27, 2008 - 17:28

FTR, my work-around for my problem was to shift the action out of nodeapi into a custom #validate function, where the $form_state IS available.

Either in your form declaration or via hook_form_alter should work.
Just FYI in case someone else is looking for clues.

#5

mrlupin - June 1, 2008 - 19:24

Subscribing, i spent the day trying to figure out how to get $form_state from hook_nodeapi with $form, I still don't get it ...

#6

j0hn-smith - June 30, 2008 - 05:34

Subscribing

#7

cmoad - July 2, 2008 - 17:08

Subscribing....

Adding a file upload field to a node form is very difficult to do without this functionality.

#8

rares - July 17, 2008 - 16:54

I'm using $_POST['form_element_id'] to get the values that used to be in global $form_values.

 
 

Drupal is a registered trademark of Dries Buytaert.