2014-12-03 114 views
1

enter image description here我有一个带有三个按钮的窗体..一个按钮是在另一个页面上编辑窗体,第二个是在现有页面上添加值,第三个是删除值..提交和编辑效果很好..现在我需要在删除按钮工作..因为它是一个按钮..我无法与$_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

我可以用两个的提交?在一种形式? – 2014-12-03 07:22:28

+1

是的,你可以看到我的答案。 – 2014-12-03 07:33:36

回答

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; 
    } 

?> 
0

错字:

变化

$name = $_REQUESR['example_text']; // this can't get value; 

要:

$name = $_REQUEST['example_text']; // this can't get value; 
+0

什么都没有发生..实际上它是'$ _REQUEST',但我错过键入它.. – 2014-12-03 07:24:46

2

更换

<a href="index.php?del"> 
    <input type="button" value="Delete" /> 
    </a> 

<input type="submit" value="Delete" name="del"/> 

给你的每个按钮的名称,以便您可以检查哪个按钮已提交

做检查删除按钮点击

if(isset($_POST['del'])) { 
} 
+0

已经有一个提交定义.. – 2014-12-03 07:25:33

+0

你可以设置多个使用不同的名称提交= name =“del” – 2014-12-03 07:26:21

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> 
+0

nice share ..但是我正在寻找PHP – 2014-12-03 08:27:00