頁面上不顯示隱藏字段。
它只是存儲文本值在value屬性中指定。
隱藏字段非常適合傳遞附加信息到服務(wù)器的形式。
<label for="hiddenField">A hidden field</label> <input type="hidden" name="hiddenField" id="hiddenField" value="" />
以下形式使用隱藏字段來存儲嘗試次數(shù)。
<?php//from w w w . j av a2s .c om
$num_to_guess = 42;
$message = "";
if (! isset ( $_POST ["guess"] )) {
$message = "Welcome!";
} else if ($_POST ["guess"] > $num_to_guess) {
$message = $_POST ["guess"] . " is too big!";
} else if ($_POST ["guess"] < $num_to_guess) {
$message = $_POST ["guess"] . " is too small!";
} else {
$message = "Well done!";
}
$guess = ( int ) $_POST ["guess"];
$num_tries = ( int ) $_POST ["num_tries"];
$num_tries ++;
?>
<html>
<body>
<?php print $message?>
Guess number: <?php print $num_tries?><br />
<form method="post" action="<?php
print $_SERVER ["PHP_SELF"]?>">
<input type="hidden" name="num_tries"
value="<?php
print $num_tries?>" /> Type your guess here: <input type="text" name="guess" value="<?php
print $guess?>" />
</form>
</body>
</html>
更多建議: