I have a content type with an image field. I need to validate this field because I need to check if user upload a real image or only a file with image’s extension (like jpg, gif, png etc). I have tried and readed 100+ things but none resolve my problem.
I have tried via “#upload_validators” with this code:
foreach ($form['field_all_images'][$form['field_all_images']['#language']] as $k => $v) { if (!is_integer($k)) continue; $form['field_all_images'][$form['field_all_images']['#language']][$k]['#upload_validators']['check_image_correct'] = array(); }
where “check_image_correct()” is a my custom function that checks via imagegetinfo()
. My problem, in this “try/case”, is that the function works/is called only for the first image. I have tried to move this function from hook_form_alter()
to an #after_build
function, without result (only the first time it works).