Simple ajax call will not allow you to send files to server no matter if form enctype is multipart. Had similar issue for couple days and been trying to look for an answer. Came up with jQuery Form Plugin as Andrey Ovcharov mentioned. But still during validation it failed. The trick is to add couple additional options to ajaxSubmit method:
, iframe:true
, url:your_ajax_url
Also, if you want file elements to be optional - make sure your elements are optional. When using multiple files, during submission prepare form to be ready to validate by looping those items and checking if $element->getFileName()
is valid string (keeping it simple len > 0
and sometimes check for not being array).
I also left $element->setAllowEmpty(true);
while testing it. Not sure if very important, but when finally got it working - left, can't do any harm :)
P.S. I know, question is 2012y, but I myself was struggling with zend form validation with optional file uploads + ajax call