多个提交按钮 [英] More than one submit button
问题描述
我在使用HTML及以上的HTML中的一个提交按钮时遇到了麻烦PHP,我试图为基于Web的计算器编写GUI.那真的很容易,但是php中的功能却并不那么容易.所以我有一个带有6个提交按钮的简单GUI:
I'm having trouble with more then one submit Buttons in HTML & PHP, i tried to code a GUI for a web-based calculator. That's realy easy, but the function in php isn't so easy. So i have this simple GUI with 6 submit buttons:
<?php
$output= isset($_POST['output']) ? $_POST['output'] : "";
function calc(){
//calculate...
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<title>Calc</title>
<style type="text/css">
.bwidth {
width: 100%;
}
</style>
</head>
<body>
<form action="calc.php">
<h1>
<u>MY Own Calculator</u>
</h1>
<table border="3px" type="box" cellspacing="5px" width="250px">
<tr style="height: 24px;">
<td colspan="3"><input type="text" name="<?php $ausgabe ?>"
value="0" style="width: 98%;" /></td>
</tr>
<tr>
<td><input class="bwidth" type="submit" name="1" value="1" /></td>
<td><input class="bwidth" type="submit" name="2" value="2" /></td>
<td><input class="bwidth" type="submit" name="3" value="3" /></td>
</tr>
<tr>
<td><input class="bwidth" type="submit" name="minus" value="-" /></td>
<td><input class="bwidth" type="submit" name="plus" value="+" /></td>
<td><input class="bwidth" type="submit" name="enter"
value="=" /></td>
</tr>
</table>
</form>
</body>
现在如何区分众多提交按钮?甚至可能有多个提交按钮?我尝试用值将按钮分开...但是它不起作用.
Now how I can differentiate these many submit buttons? It's even possible to have more than one submit button? I tried it to seperate the buttons by the value... but it didn't work.
然后sb有了一个主意,我如何才能向文本字段中的现有值添加一个值?因此,我可以按按钮1,它将在文本字段中写入1;当我按按钮2时,它将添加数字2,因此它将为"12"?
And sb has an idea how i can add a value to an existing value in the textfield? So i can push button 1 and it will write 1 in the textfield and when i will push button 2 it will add the number 2 so it will a "12"?
感谢所有建议!
推荐答案
您可以尝试使用 isset($ _ GET ['input_name'])
来验证设置了哪个按钮.
You can try to verify which button is set using isset($_GET['input_name'])
.
或者您可以命名其他输入:
Or you could name different the inputs:
<form action="calc.php">
<h1>
<u>MY Own Calculator</u>
</h1>
<table border="3px" type="box" cellspacing="5px" width="250px">
<tr style="height: 24px;">
<td colspan="3"><input type="text" name="<?php $ausgabe ?>"
value="0" style="width: 98%;" /></td>
</tr>
<tr>
<td><input class="bwidth" type="submit" name="digit" value="1" /></td>
<td><input class="bwidth" type="submit" name="digit" value="2" /></td>
<td><input class="bwidth" type="submit" name="digit" value="3" /></td>
</tr>
<tr>
<td><input class="bwidth" type="submit" name="operation" value="-" /></td>
<td><input class="bwidth" type="submit" name="operation" value="+" /></td>
<td><input class="bwidth" type="submit" name="operation" value="=" /></td>
</tr>
</table>
</form>
在您的函数中:
function calc(){
$op = isset($_GET['operation']) ? $_GET['operation'] : null;
switch ($op) {
case "+": .... ; break;
case "-": .... ; break;
case "=": .... ; break;
default: "not supported";
}
}
这篇关于多个提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!