Back to Top
The nuts and bolts for
Creative web development

Optional Upload?

Question:


What can i do if the file that the users can upload is optional ?
The behavior convert required the field in my form, i need it optional !

Answer:


Try deleting the form onSubmit action. This will disable the empty filename check - but it will also disable the Allowed Extensions check.

In the next version of Pure Upload this will be an option.

Share this Article

Comments

RE: Optional Upload Fix

Hi,  I may be just plain stupid but I do not understand your fix for the optional upload?  Please can you explain exactly what I have to do?

Many Thanks

Phil

RE: Optional Upload Fix

Very good Sam - this does the job even better!

Optional Upload Fix

Commenting out the following foure lines (marked in red)

 in the check extensions script worked for me, as follows

comments?

------------------------
function checkFileUpload(form,extensions) { //v1.0
  document.MM_returnValue = true;
  if (extensions && extensions != '') {
    for (var i = 0; i<form.elements.length; i++) {
      field = form.elements[i];
      if (field.type.toUpperCase() != 'FILE') continue;
//      if (field.value == '') {
//       alert('File is required!');
//        document.MM_returnValue = false;field.focus();break;
//      }
      if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {
        alert('This file is not allowed for uploading!');
        document.MM_returnValue = false;field.focus();break;
  } } }
}

-------------------------------

SAM