Jump to content

File upload validation


unplugged_web

Recommended Posts

I've got a form that requires people to upload a photo of themselves. I'm using this to get the photo:

<input type="file" name="photo" id="photo" />

and this to validate it but it's still allowing people to send the form without a photo. All of the other validation works it's just the photo part.

<script type="text/javascript">   function validate_form(){        var f = document.getElementById('fname');        var l = document.getElementById('lname');        var e = document.getElementById('email');        var p = document.getElementById('phone');        var ph = document.getElementById('photo');        var fAlert = "Please enter your first name";        var lAlert = "Please enter your last name";        var eAlert = "Please enter a valid email address";        var pAlert = "Please enter a contact number";        var phAlert = "Please provide a recent photo";        var em;         if (!f.value) {                 alert (fAlert);                 return false;         }         if (!l.value) {                 alert (lAlert);                 return false;         }         if (!e.value) {                 alert (eAlert);                 return false;         }         em = e.value.match(/[@.]/g);         if ((!em) || (em.length < 2)) {                 alert (eAlert);                 return false;         }         if (!p.value) {               alert (pAlert);               return false;         }         if (!ph.value) {                 alert (phAlert);                 return false;         }         return true;   }   </script>

Thanks

Link to comment
Share on other sites

You mean -- selects a file -- before it's submitted. And as I say it looked fine in FF28.

if (!ph.value) {    alert ('bad file:['+ph.value+']');    return false;}else{    alert ('good file:['+ph.value+']');}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...