0

I have a problem with validating mutiple file inputs. Whenever i submit, only the first / first used field is validated.

HTML:

<html>
<head>
</head>
<body>
...
<tr>
<td>Photo1:</td>
<td> <input type="file" class="ipfile" name="pic[]" /> </td>
</tr>
<tr>
<td>Photo2:</td>
<td> <input type="file" class="ipfile" name="pic[]" /> </td>
</tr>
<tr>
<td>Photo3:</td>
<td> <input type="file" class="ipfile" name="pic[]" /> </td>
</tr>
...
</body>
</html>

JS:

<script type="text/javascript">
  $(document).ready(function(){

    $("#fnpMain").validate(
    {
    rules:{
        Telefon:{required:true, exactlength:9, digits:true}
    }}
    );

    $("input.ipfile").each(function(){
       $(this).rules("add", {
           required:true,
           accept: "jpg|jpeg"
       });                   
    });
  });
</script>
John
  • 1,619
  • 8
  • 24
  • 34

1 Answers1

1

I think, this is what you are expecting.

LIVE DEMO

I have used this jquery-plugin-validation file from this bassistance.de site.

HTML:

<form id="fnpMain">
    <table>
        <tr> 
            <td>Photo1:</td> 
            <td> 
                <input type="file" class="ipfile" name="pic0" /> 
            </td> 
        </tr> 
        <tr> 
            <td>Photo2:</td> 
            <td> 
                <input type="file" class="ipfile" name="pic1" /> 
            </td> 
        </tr> 
        <tr> 
            <td>Photo3:</td> 
            <td> 
                <input type="file" class="ipfile" name="pic2" /> 
            </td> 
        </tr> 
    </table>
     <input type="submit" value="Submit"/>

</form>

JS:

$("#fnpMain").validate();

$("input.ipfile").each(function(){        
    $(this).rules("add", {            
        required:true,            
        accept: "jpg|jpeg"        
    });                        
});
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • Yes, this is what i want, BUT unfortunately, name attributes have to be "pic[]". It is an array for later php use. – John May 28 '12 at 14:20