Php 通过单击按钮从窗体获取值?不服
我有一张有三个按钮的表格。。一个按钮是在另一个页面中编辑表单,第二个按钮是在现有页面上添加值,第三个按钮是删除值。。提交和编辑效果很好。。现在我需要处理删除按钮。。因为它是一个按钮。。我无法使用Php 通过单击按钮从窗体获取值?不服,php,html,ajax,Php,Html,Ajax,我有一张有三个按钮的表格。。一个按钮是在另一个页面中编辑表单,第二个按钮是在现有页面上添加值,第三个按钮是删除值。。提交和编辑效果很好。。现在我需要处理删除按钮。。因为它是一个按钮。。我无法使用$\u POST或$\u get和$\u REQUEST获取值我做过类似的操作 <form method="POST"> <input type="text" name="example_text" /> <a href="index.php?del">
$\u POST
或$\u get
和$\u 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;
}
?>
打字错误:
改变
$name = $_REQUESR['example_text']; // this can't get value;
致:
替换
<a href="index.php?del">
<input type="button" value="Delete" />
</a>
试试这个:
<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;
}
?>
试试这个,它会很好地工作:
<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>
功能按钮1()
{
var r=document.getElementById('example_text')。值;
window.location=“getdetails.php?data=“+r;
}
功能按钮2()
{
var r=document.getElementById('example_text')。值;
window.location=“getdetails.php?data=“+r;
}
我可以使用两个提交吗?在一个表单中?是的,你可以看到我的答案。你可以使用不同的名称设置多个提交,如name=“del”nice share。。但是我在找php
if(isset($_POST['del'])) {
}
<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;
}
?>
<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>