0
我一直在研究這個簡單的「獲取」表格一個多星期,並且正在給叔叔打電話。我希望表單在用戶點擊「提交」之前回顯GREETING常量,即頁面首次加載時。即使沒有點擊'提交','沒有用戶輸入'的響應加載並忽略了GREETING。這是我的代碼w/out if(isset($ _ GET [「submit」]))。
當我添加if(isset ..)GREETING常量加載但所有其他操作都被忽略。
代碼瓦特/ isset:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A Simple Get Form</title>
</head>
<body>
<form name="GetForm" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="GET">
1) What are the colors of the U.S. Flag?<br>
<input type="radio" name="Question1" value="a" />a) red, white and blue<br />
<input type="radio" name="Question1" value="b" />b) yellow, red and blue<br />
<input type="radio" name="Question1" value="c" />c) blue, green and amber <br>
<input type="submit" value="GO" /><input type="reset" value="RESET" />
</form>
</body>
</html>
<?
define(ERROR, 'No answer was input for this question. Please select and answer.');
define(GREETING, 'Welcome to my simplest of php forms.');
$answer1=$_GET['Question1'];
if($answer1=="a")
{echo "You are correct."; }
elseif ($answer1=="")
{echo ERROR. "" ; }
elseif ($answer1=="b" || $answer1=="c")
{echo "Your answer was incorrect."; }
else {echo GREETING. ""; }
?>
這裏是與if(isset代碼..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A Simple Get Form</title>
</head>
<body>
<form name="GetForm" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="GET">
1) What are the colors of the U.S. Flag?<br>
<input type="radio" name="Question1" value="a" />a) red, white and blue<br />
<input type="radio" name="Question1" value="b" />b) yellow, red and blue<br />
<input type="radio" name="Question1" value="c" />c) blue, green and amber <br>
<input type="submit" value="GO" /><input type="reset" value="RESET" />
</form>
</body>
</html>
<?
define(ERROR, 'No answer was input for this question. Please select and answer.');
define(GREETING, 'Welcome to my simplest of php forms.');
$answer1=$_GET['Question1'];
if(isset($_GET["submit"]))
{
if($answer1=="a")
{echo "You are correct."; }
elseif ($answer1=="")
{echo ERROR. "" ; }
elseif ($answer1=="b" || $answer1=="c")
{echo "Your answer was incorrect."; }
}
else {echo GREETING. ""; }
?>
由於當我改變形式的方法爲「POST」和添加的($ _SERVER [ 'REQUEST_METHOD'] =='POST')它工作得非常好。我無法使用您的建議獲取$ _GET表單方法。那謝謝啦! –