我有一个带有三个按钮的表单..一个按钮是在另一个页面中编辑表单,第二个是在现有页面上添加值,第三个是删除它的值..提交和编辑效果很好..现在我需要处理删除按钮..因为它是一个按钮..我无法通过$_POST
或$_GET
获得价值而$_REQUEST
我做了类似的事情。 。
<form method="POST">
<input type="text" name="example_text" />
<a href="index.php?del">
<input type="button" value="Delete" />
</a>
<!-- works fine !-->
<a href="someotherpage.php">
<input type="button" value="edit" />
</a>
<!-- works fine !-->
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit']))
{
echo "submit can get value by $_POST";
$name = $_POST['example_text'];
}
if(isset($_GET['del']))
{
$name = $_REQUEST['example_text']; // this can't get value;
$name = $_POST['example_text']; // this can't get value;
$name = $_GET['example_text']; // this can't get value;
}
?>
答案 0 :(得分:2)
替换
<a href="index.php?del">
<input type="button" value="Delete" />
</a>
到
<input type="submit" value="Delete" name="del"/>
为每个按钮指定一个名称,以便检查已提交的按钮
单击检查删除按钮
if(isset($_POST['del'])) {
}
答案 1 :(得分:1)
尝试一下它会正常工作:
<html>
<head>
<script>
function button1()
{
var r= document.getElementById('example_text').value;
window.location="getdetails.php?data="+r;
}
function button2()
{
var r= document.getElementById('example_text').value;
window.location="getdetails.php?data="+r;
}
</script>
</head>
<body>
<form method="POST">
<input type="text" name="example_text" id="example_text"/>
<a href="index.php?del">
<input type="button" value="Delete" onclick="button1()"/>
</a>
<!-- works fine !-->
<a href="someotherpage.php">
<input type="button" value="edit" onclick="button1()"/>
</a>
<!-- works fine !-->
<input type="submit" name="submit" />
</form>
</body>
</html>
答案 2 :(得分:0)
错字:
更改
$name = $_REQUESR['example_text']; // this can't get value;
要:
$name = $_REQUEST['example_text']; // this can't get value;
答案 3 :(得分:0)
试试这个:
<form method="POST">
<input type="text" name="example_text" />
<input type="submit" name="delete" value="Delete" />
<a href="someotherpage.php">
<input type="button" name="edit" value="Edit" />
</a>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_REQUEST['submit']))
{
$name = $_REQUEST['example_text'];
echo "Submit method: ".$name;
}
if(isset($_REQUEST['delete']))
{
$name = $_REQUEST['example_text'];
echo "Delete method: ".$name;
}
?>