发布提交按钮值

时间:2012-08-18 21:30:03

标签: html html5

在我正在制作的表格中,我需要通知处理php脚本点击了什么按钮。我有三个按钮,新建,保存和删除。我希望表单和所有按钮值都要发布但是表单+点击的按钮只发布。我在这里查看html规范http://www.w3.org/TR/html401/interact/forms.html#submit-format但是我还没有找到一些解释,如果这应该是预期的。我有这个PHP脚本

<?php
/**
tpost.php
*/
//Buttons
$new = $_POST['new'];
$save = $_POST['save'];
$delete = $_POST['delete'];
//Error: Notice: Undefined index: save in C:\wamp\www\form-dev\troll.php on line 7
//Forms
$city = $_POST['city'];
$zip = $_POST['zip'];
$cs = $_POST['cs'];
//Error: Notice: Undefined index: save in C:\wamp\www\form-dev\troll.php on line 8
//Buttons echo
echo '<b>'.$new.'</b>' .'<br/>';
echo '<b>'.$save.'</b>' .'<br/>';
echo '<b>'.$delete.'</b>' .'<br/>';

//Forms echo

echo '<b>'.$city.'</b>' .'<br/>';
echo '<b>'.$zip.'</b>' .'<br/>';
echo '<b>'.$cs.'</b>' .'<br/>';
?>

这是我正在使用的html

<!Doctype html>
<head>
<meta charset="uft-8">
<title>Buttons post</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<style type="text/css">
label{
width:15%;
float:left;
font-style:italic;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
   $('.inew').on("click",function()
    {
    alert('new');
    });
     $('.isave').on("click",function()
    {
    alert('save');
    });
     $('.idelete').on("click",function()
    {
    alert('delete');
    });
    });
</script>
</head>
<body>
<form action="tpost.php" name="troll" method="post">
<label>Enter Your City</label><input type="text" name="city" value="some-city"/><br/><br/><br/>
<label>Enter Your Neighbourhood</label><input type="text" name="zip" value="my-zip" /><br/><br/><br/>
<label>Enter Your Nearest Shopping Mall</label><input type="text" name="cs" value="shop-here" /><br/>
<br/><hr/><br/>
<br/>
<hr/>
<input class="inew" type="submit" name="new" value="new" />
<input class="isave" type="submit" name="save" value="save" />
<input class="idelete" type="submit" name="delete" value="delete" />
</form>
</body>
</html>

对此有何解释?。

1 个答案:

答案 0 :(得分:1)

我在这里找到了答案http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2

它说

  

如果表单包含多个提交按钮,则仅激活   提交按钮成功。

相关问题