0
我試圖驗證「修改」表單。數據是從數據庫中接收的,所以當然我必須把它放在一段時間。驗證不起作用的表單
<?php
while ($row = mysql_fetch_array($categories))
{
?>
<form name="adminEditCategory" action="../db/adminModifyCategory.php" method="POST" enctype="multipart/form-data" >
<tr>
<td>
<input type="text" name="id" value="<?php print $row['id']; ?>" readonly="readonly" style="width: 20px;" />
</td>
<td> <input type="text" name="name<?php print $row['id']; ?>" value="<?php print $row['name']; ?>" /><span></span>
</td>
<td> <img src="../utils/getLogoCategory.php?id=<?php print $row['id']; ?>" style="max-width:40px; max-height:40px; float: left; margin-bottom: 10px;" align="left" /> </td>
<td>
<input type="file" name="attachment<?php print $row['id']; ?>" value="" style="float: right; "><span></span>
</td>
<td> <?php print date('d-m-Y', strtotime($row['added_date'])); ?>
</td>
<td>
<select width="294" name="is_deleted<?php print $row['id']; ?>" style="width: 50px;">
<?php
foreach($is_deleted as $id=>$name)
{
?>
<option value="<?php print $id; ?>" <?php if($id == $row['is_deleted']) print "selected= 'selected'"; ?> ><?php print $name; ?></option>
<?php
}
?>
</select><span></span>
</td>
<td> <input type="submit" value="Modifica" name="Edit" class="button" onClick="return validateEditCategory(<?php print $row['id']; ?>)" />
<input type="submit" value="Sterge" class="button" name="Delete" onClick="return validateDeleteCategory()">
</td>
</tr></form>
<?php
}
?>
這是驗證碼:
function validateEditCategory(Id) {
var valid;
valid = true;
// alert (document.forms["adminEditCategory"]["name"+Id].name);
valid *= checkNume(document.forms["adminEditCategory"]["name"+Id]);
valid *= checkIsFileGol(document.forms["adminEditCategory"]["attachment"+Id]);
return valid > 0;
}
驗證工作,但只有第一行。我不明白爲什麼它不驗證其餘的行。