我正在尝试验证“修改”表单。数据是从数据库接收的,所以我当然要把它放一段时间。
<?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;
}
验证有效,但仅适用于第一行。我无法理解为什么它不验证其余的行。
答案 0 :(得分:1)
尝试更改此<form name="adminEditCategory" action=
这个<form name="adminEditCategory<?php print $row['id']; ?>" action=
和
这document.forms["adminEditCategory"]
对此document.forms["adminEditCategory" + Id]
。
<input name='id'>
中传递了ID。但这不是必要的,只是更短,更合乎逻辑。