大家好,我有这个简单的工作形式,以及更新和删除工作的功能,但我似乎无法想出一种方法,使它们在一种形式同时工作......这就是我在做什么
<form id ='UDAssignment' method ='get' name='UDAssignment'>
<input id ='action' type ='hidden' name ='action' value ='updateMessageFromSimpleForm' />
<label for='fId'> Id </label>
<input id ="fId" type='number' name ='fId' readonly/>
<label for='fTitle'> Title </label>
<input id ="fTitle" type='text' name ='fTitle'/>
<label for='fModule'> Module </label>
<input id ="fModule" type ='text' name ='fModule'/>
<label for='fDescription'> Description </label>
<textarea rows ='4' id ='fDescription' type ='text' name ='fDescription'> </textarea>
<label for='fDueDate'> DueDate </label>
<input id ="fDueDate" type='date' name ='fDueDate'/>
<div class ="form-group">
<div class ="controls">
<button type ="submit" class ="btn btn-primary"> Update </button>
<button type ="submit" class = btn btn-default"> Delete </button>
</div>
</div>
</form>
所以基本上在设置更新操作时我想知道如果单击删除按钮,如何设置要删除的操作
答案 0 :(得分:0)
您需要添加一些客户端代码。理想情况下,它将是一个单独的JavaScript函数,具有验证等。但最简单的是,您可以将删除按钮修改为:
<button type ="submit" class = "btn btn-default" onclick="document.getElementById('action').value = 'deleteMessageFromSimpleForm';" > Delete </button>
在按钮提交之前 - 它调用click事件的处理程序,它将隐藏字段的值更改为新操作。
答案 1 :(得分:0)
使用javascript更改其功能
<input type="button" value="update" onclick="update()" />
<input type="button" value="delete" onclick="delete()" />
的javascript:
function update(){
document.UDAssignment.action = 'updateMessageFromSimpleForm';
document.getElementById('UDAssignment').submit();
}
function delete(){
document.UDAssignment.action = 'deleteMessageFromSimpleForm';
document.getElementById('UDAssignment').submit();
}
答案 2 :(得分:0)
我正在使用php。 检查代码:
<?php
if(isset($_GET['update'])){
echo "update";
//update code goes here
}
if(isset($_GET['delete'])){
echo "delete";
//delete code goes here
}
?>
<form id ='UDAssignment' method ='get' name='UDAssignment' action="">
<input id ='action' type ='hidden' name ='action' value ='updateMessageFromSimpleForm' />
<label for='fId'> Id </label>
<input id ="fId" type='number' name ='fId' readonly/>
<label for='fTitle'> Title </label>
<input id ="fTitle" type='text' name ='fTitle'/>
<label for='fModule'> Module </label>
<input id ="fModule" type ='text' name ='fModule'/>
<label for='fDescription'> Description </label>
<textarea rows ='4' id ='fDescription' type ='text' name ='fDescription'> </textarea>
<label for='fDueDate'> DueDate </label>
<input id ="fDueDate" type='date' name ='fDueDate'/>
<div class ="form-group">
<div class ="controls">
<button type ="submit" name="update" > Update </button>
<button type ="submit" name="delete"> Delete </button>
</div>
</div>
</form>