Hi All,

This seems to be a real basic question but i really need to understand and get this to work:

In user profile i have added a field where the user uploads a file. This is working as planned (of course).

Now i want a process, almost like a virus scanner or validation to work on the file
and if it fails it should alert the uploading authenticated user that there was a problem with the file and therefore simply reject the file.

The validation/analyzing should be done serverside.

What hook should be used and where? In theme or in a module?
Its ONLY one specific field in the user profile that needs this validation,
other files thats uploaded in other fields should be unaffected.

Comments

arne_hortell’s picture

I have already the validation functionality in place, i only need to get the hook things to work.

So a extremely short explanation will do, like

In your module do
foo_hook_something

or in your theme do
foo_hook something

Please?

Nothing is impossible, the impossible just takes a little more time

dman’s picture

First, this is functionality, not a layout thing, so it's 100% a module, not a theme task.

In general,
You make yourself a small module, and implement probably only HOOK_form_alter().

In your hook_form_alter function, you would
- ensure it's the right form (check the form ID)
- scan the $form object for the element that you want to target.
- add a #element_validate callback that calls your preferred custom check.

However, file uploads are a bit more complex than most other value checks, so there may be more to it. throw some generous dpm(get_defined_vars()) into your func so you can see what's available.

arne_hortell’s picture

Thanks for your support

Nothing is impossible, the impossible just takes a little more time