<form action=" " name="formset" method="post" enctype="multipart/form-data" autocomplete="off">
<div class="form-group">
<label for="avatar">编号</label>
<input type="text" class="form-control" id="id" name="id" value="<?php echo $user['id']?>" readonly>
</div>
<div class="form-group">
<label for="avatar">头像</label>
<input type="file" class="form-control" id="avatar" name="avatar" accept="image/*">
</div>
<div class="form-group">
<label for="name">姓名</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo $user['name']; ?>">
</div>
<div class="form-group">
<label for="gender">性别</label>
<select class="form-control" id="gender" name="gender">
<option value="-1">请选择性别</option>
<option value="1"<?php echo $user['gender'] === '1' ? ' selected': ''; ?>>男</option>
<option value="0"<?php echo $user['gender'] === '0' ? ' selected': ''; ?>>女</option>
</select>
</div>
<div class="form-group">
<label for="birthday">生日</label>
<input type="date" class="form-control" id="birthday" name="birthday" value="<?php echo $user['birthday']; ?>">
</div>
<input type="submit" class="btn btn-primary" onclick="F_submit()" value="保存"></input>
</form>
通过js代码来实现这个目的:
<script>
function F_submit(){
document.formset.action="<?php echo $_SERVER['PHP_SELF']; ?>";
document.formset.submit();
<?php if(!empty($error_message)):?>
document.formset.action="savechange.php";
document.formset.submit();
<?php endif;?>
}
</script>
这里是把form表单中的数据提交给当前页面和savechange.php页面