1

I have a form where users upload images. When an image is submitted it is validated against various criteria. If the validation fails the user is returned to the form but the failed file is still showing in the file upload element with the remove button.

I have been trying to find a way (with no success so far) to automatically remove the file if it fails validation so the user does not have to do it.

It doesn't bother me but the client has requested it so I need to do it somehow.

Any ideas?

1
  • please come your validate handler here, you can do it in your validation handler – Yuseferi Nov 17 '15 at 6:18
0
hook_field_widget_form_alter(&$element, &$form_state, $context)

this may help you to validate your file and if validation criteria fails return empty form element.

2
  • Thanks, I haven't tried that. I'll have a look at that hook and see what I can do with it. – coranda Nov 17 '15 at 8:03
  • Was this the solution? – stefgosselin Jan 6 '16 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.