Hi all,
I am having some trouble getting this piece of code to work. It is run upon submitting a content type with a file field called 'picture'.
function picturehost_validate(&$node) {
$file = picturehost_validate_file(file_check_upload('picture'), 'picture');
if (!$file->error) {
form_set_value(array('#parents' => array('picture')), (array) $file);
} else {
form_set_error('picture', $file->error);
}
}
The picturehost_validate_file function checks to see if the uploaded file is an image that meets certain requirments. If true, it returns the $file object without error, else an error text is added to the $file object. All works great and a print_r($file) shows that file validation works as expected. The code also reaches the form_set_value line, but that is where problems arise. It is my understanding that this line should add the content of the $file object to the $node object, but this doesn't happen. $node->picture remains empty.
Any clues as to what I might be doing wrong?
Comments
Why don't you set the $node object directly?
like this:
And then in the _submit function you can do what you need to do with the $node object...
Cheers, pip
Sorry posted it twice...
Cheers, pip
Actually...
... that is a really good question. I have no idea why that obviously simply idea slipped my mind. Inserting it immediately into $node appears to do the trick.
Thanks!