Page 1 of 1

Validate multiple uploads

Posted: Thu Apr 27, 2006 7:25 pm
by sulen
I have a multiple image upload module which has 4 upload textboxes. I need to validate the upload boxes and I am not sure how to do it as the field name is an array name called imagefile[] instead of something static. Any help will be appreciated. Thanks

The general js validation I do for select boxes are as under

Code: Select all

<script language="JavaScript">
function validSelect(formField,fieldLabel)
{
  var result = true;
  if (formField.selectedIndex == 0) 
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
return result;
}
unction validateForm(theForm)
{
// Start ------->
if (!validSelect(theForm.fieldname,"label"))
return false;
// <--------- End
return true;
}
</script>
The multiple image upload code is as under

Code: Select all

<form enctype="multipart/form-data" action="classifieds.php?action=addad3&in=4" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr> 
<td width="30%" align="right"><strong>image to upload:</strong></td>
<td width="80%"> <input name="imagefile[]" id="imagefile[]" type="file" class="txtbox" size="50"></td>
</tr>
</table>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr bgcolor="#CCCCCC"> 
<td nowrap class="text"><a href="classifieds.php?action=home" class="text">< cancel</a></td>
<td class="text" align="right"> 
<input class='btn' onMouseOver="this.className='btn btnhov'" onMouseOut="this.className='btn'" type="submit" name="submit" value="upload and finish">
</td>
</tr>
</table></td>
</form>

Posted: Thu Apr 27, 2006 11:10 pm
by feyd
You could give them unique ID values...

I hope this isn't your only form of validation on the uploads.