Closed (fixed)
Project:
Examples for Developers
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
26 Nov 2009 at 05:54 UTC
Updated:
29 Dec 2009 at 14:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
jhodgdonJust to clarify, in PHP 4, the called function determines whether an object is passed by value or reference (in PHP5, it is always by reference). In other words, if I make an example_validate() function and put &$node as the first argument, then that $node will be passed in by reference.
However, as noted in the hook_validate documentation, "Changes made to the $node object within a hook_validate() function will have no effect." (this is because the $node object that is passed in, by reference or not, is not used after that in the calling function).
So you are correct that the node_example_validate() function is not going to work when it sets the quantity to zero. It should be following the instructions in hook_validate()'s doc and using the form state to change the value.
Moving to correct issue queue (we are maintaining the example modules now in a separate project).
Comment #2
ilo commentedThe form sets empty value as 0 and I was about to introduce a check for $node->quantity no hook_insert and hook_update, but this is the purpose of hook_validate, so I just removed the parameter by reference and the code modifying $node->quantity.
Comment #3
ilo commentedcommitted to DRUPAL-6--1.
Comment #4
jhodgdonIt might be useful for the example to show how to set a new value for something using the form state, as an illustration.
Comment #5
ilo commentedSorry, jhodgdon, I can't follow you. It is the $form, not the $form_state what is passed to hook_validate. Do you have something in mind? can you point me an example of this form change?
Comment #6
jhodgdonTrue about $form... although is $form_state part of $form? If not, then the advice here http://api.drupal.org/api/function/hook_validate/6 about calling form_set_value() is useless.
Our status changes crossed paths...