I am using Drupal 4.7b4 and am having a problem with hook_nodeapi('validate'...) that I am really hoping someone can shed some light on.
I am using hook_nodeapi and hook_form_alter to add an image upload function to some of my existing nodetypes. My code works fine except if I preview a node before submitting it.
The problem is that hook_nodeapi('validate'...) is being called multiple times. My code looks as follows:
case 'validate':
if ($file = file_check_upload('nodeimage_upload'))
{
$file = file_save_upload('_upload', _get_filename($file->filename), FILE_EXISTS_RENAME);
...
}
The first time $op='validate' is called, everything works fine, except that file_save_upload() removes the temporary file created when the node is submitted.
What this means is that for every subsequent call of hook_nodeapi('validate'...), I get the following error:
"The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename."
I have read the forums and everthing else that I can find in the docs and I still cant find out how to fix my problem. Very similar code in 4.6 worked fine. Is this a bug, a new feature introduced in 4.7 or simply a huge gap in my understanding?
The sequence of nodeapi calls I am getting is as follows:
- load
- prepare
- validate
- view
- validate