【发布时间】:2016-03-29 22:16:36
【问题描述】:
我不知道如何在我的表单中添加“是”和“否”按钮,以便当用户插入并按下提交按钮时,数据会从服务器端脚本发回并返回给用户,然后用户单击是或否按钮来批准信息。如果是,程序应该提出异议,谢谢
<html>
<head>
<title>Test1-1</title>
</head>
<body>
<?php
if (filter_has_var(INPUT_POST, "name")){
$name = filter_input(INPUT_POST, "name");
print "<p>Hi $name, </p>";
}
if (filter_has_var(INPUT_POST, "id")){
$id = filter_input(INPUT_POST, "id");
print "<span>Your Employee ID is $id</span>";
}
if (filter_has_var(INPUT_POST, "office")){
$office = filter_input(INPUT_POST, "office");
print "<span>, your office is room $office</span>";
}
if (filter_has_var(INPUT_POST, "os")){
$os = filter_input(INPUT_POST, "os");
print "<span>, and your OS is $os</span>";
}
else {
//there's no input. Create the form
print <<< HERE
<form action ="" method = "post">
<fieldset>
<label>Enter your name</label>
<input type = "text"
name = "name"/><br>
<label>Employee ID</label>
<input type = "text"
name = "id"/><br>
<label>Office Room Number</label>
<input type = "text"
name = "office"/><br>
<label>Oberating System on the Office Computer</label>
<input type = "text"
name = "os"/><br>
<button type = "submit">
submit
</button>
</fieldset>
</form>
HERE;
}// end 'value exists' if
?>
</body>
</html>
【问题讨论】:
-
您可能会想要使用 ajax,这样您就可以将表单数据发送到服务器端代码,然后当它返回时更新 html,以便用户看到是/否按钮。从那里你将需要更多的 ajax 代码来处理当他们点击是/否时发生的事情。