By Salma on
The subject is the question: "How to pass data from hook_validate to hook_insert?". Specifically I want to pass info about a file uploaded in hook_validate. I could do a second file_save_upload in hook_insert but I want to avoid that solution.
Any hint appreciated.
Comments
If you are talking about
If you are talking about form, use form_state for passing data.
I am not talking about forms...
Thanks for your answer. I'm not talking about forms though, only hooks validate and insert.
the word hook is an abstract
the word hook is an abstract term, you need to replacer it with an actual type of module which may be a form or whatever.
I don't understand...
Sorry, I don't understand what you're saying. In my understanding hook_validate is a *real* hook and hook_form_validate is not (see http://drupal.org/node/336627).
Anyway, my question remains: is there a way to pass data between mymodule_validate and mymodule_insert?
regards.
you can use persistent
you can use persistent variables to pass data. You can also use hook parameters to pass data depending on the type of module and type of hook.
hook parameters?
Yes I thought about persistent variable but it should have a unique name based on user id and node id, I know it is possible but I was looking for a more "elegant" solution. That said, can I ask you to be more specific about hook parameters? A simple code example would be great.
Try passing &$form after
Try passing &$form after $node in hook_insert(). You may be able to pass data from hook_validate() to hook_insert() by attaching data to the $form array. I'm not entirely sure of that, but I think I have done it in the past.
Contact me to contract me for D7 -> D10/11 migrations.
use custom validation handler
The solution has been given on http://drupal.org/node/356123: use a custom validation handler so to have acces to $form_data (which is not a parameter of hook_validate).