[英]php, submit 2 buttons in same page
I would to submit 2 buttons in same php page, every button show deferent message on label, 我想在同一个php页面中提交2个按钮,每个按钮在标签上显示不同的消息,
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<title>Test Submit 2 buttons</title>
<body>
<?php
$add_result = "";
if (isset($_POST['addnews']))
{
$add_result = "Hello, add new news";
}
if (isset($_POST['deletenews']))
{
$add_result = "Hello, delete all news";
}
?>
<br /> <br /> <br /> <br /> <br /> <br/>
<form accept-charset="utf-8" method="POST" dir="rtl" style="text-align:center" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label>Enter the news before click on any button::</label>
<br /> <br />
<input type="text" name="news_text" size="100" id="partNumber" required/>
<br /> <br /> <br /> <br />
<input type="submit" name="addnews" id="round" value="Add" />
<br /> <br/> <br />
<input type="submit" name="deletenews" id="round" value="Remove" />
<label for="message">
<?php echo $add_result; ?>
</label>
</form>
<style type="text/css">
input#round{
....
}
</style>
I used PHP_SELF in the form, I want the result show directly after click on any button without change the page 我在表单中使用了PHP_SELF,我希望在点击任何按钮后直接显示结果而不更改页面
Thanks 谢谢
Either do some tricky js stuff, like changing some hidden input value or form action etc. 要么做一些棘手的js,比如更改一些隐藏的输入值或表单动作等。
Or just keep it simple and use radio boxes 或者只是保持简单并使用无线电盒
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.