Download & Extend

hook_validate documentation suggests form_set_value(), but not possible

Project:Drupal core
Version:8.x-dev
Component:documentation
Category:bug report
Priority:normal
Assigned:nenne
Status:active
Issue tags:needs backport to D6, needs backport to D7

Issue Summary

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.

Comments

#1

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.

#2

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

#3

Assigned to:Anonymous» nenne

#4

Status:active» needs review

Removed the erronous part and corrected a MT.

AttachmentSizeStatusTest resultOperations
hook_validate_doc_correction-326564.patch1.38 KBIdlePASSED: [[SimpleTest]]: [MySQL] 18,734 pass(es).View details | Re-test

#5

Status:needs review» reviewed & tested by the community

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

Thanks!

#6

Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#7

Status:fixed» closed (fixed)

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

#8

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

#9

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.

#10

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.

nobody click here