The hook_validate documentation seems to be invalid in several ways. There is a paragraph that reads:
Changes made to the $node object within a hook_validate() function will have no effect. 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().
However hook_nodeapi($op='submit') does not seem to exist, and also form_set_value is not an option, as from hook_validate you don't have access to a form_state variable you can change.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | hook_validate_doc_correction-326564.patch | 1.38 KB | Anonymous (not verified) |
Comments
Comment #1
jhodgdonThe hook_nodeapi() reference has already been fixed.
I agree on what you're saying about using form_set_value() though. This needs to be fixed in Drupal 7, then having the fix backported to Drupal 6.
Comment #2
jhodgdonMore discussion on #336305: Documentation error for hook_validate() regarding form_set_value(), which I just marked as a duplicate of this issue.
Comment #3
Anonymous (not verified) commentedComment #4
Anonymous (not verified) commentedRemoved the erronous part and corrected a MT.
Comment #5
jhodgdonLooks good to me. Assuming the test bot agrees...
Thanks!
Comment #6
dries commentedCommitted to CVS HEAD. Thanks.
Comment #8
jhodgdonWhoops. In investigating #1196720: hook_node_validate documentation wrongly suggests set_form_value? I realized that this argument about $form_state not existing doesn't apply to Drupal 7/8 (the $form_state arg is there in Drupal 7/8). So maybe this fix shouldn't have been done for Drupal 7?
Also, whatever is correct for hook_validate should be done for hook_node_validate too.
Also, this fix never got backported to Drupal 6, where $form_state isn't there in either hook_validate() or hook_nodeapi($op = 'validate').
Comment #9
jhodgdontagging, also note that the person who reported #1196720: hook_node_validate documentation wrongly suggests set_form_value? said that using form_set_value() didn't work.
Comment #10
hansfn commentedBut that person, me, didn't try very hard to make form_set_value work - I had already found this issue and kind of thought that form_set_value shouldn't work.
Comment #11
jhodgdonI'm going through some old issues... This doesn't apply to 8.x any more (hook doesn't exist there). I think what is in 7.x is fine. And we aren't really fixing 6.x docs issues any more. So just setting this back to closed(fixed).