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.

CommentFileSizeAuthor
#4 hook_validate_doc_correction-326564.patch1.38 KBAnonymous (not verified)

Comments

jhodgdon’s picture

Title: hoook_validate documentation incorrect in several ways » hook_validate documentation suggests form_set_value(), but not possible
Version: 6.x-dev » 7.x-dev

The 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.

jhodgdon’s picture

More discussion on #336305: Documentation error for hook_validate() regarding form_set_value(), which I just marked as a duplicate of this issue.

Anonymous’s picture

Assigned: Unassigned »
Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new1.38 KB

Removed the erronous part and corrected a MT.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Assuming the test bot agrees...

Thanks!

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev
Status: Closed (fixed) » Active

Whoops. 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').

jhodgdon’s picture

tagging, 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.

hansfn’s picture

But 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.

jhodgdon’s picture

Version: 8.0.x-dev » 7.x-dev
Issue summary: View changes
Status: Active » Closed (fixed)

I'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).