PHP表单TextField

2018-02-22 16:40 更新

PHP教程 - PHP表单TextField

文本输入字段允许用户输入单行文本。

值属性

您可以选择使用 value 属性使用初始值预填充字段。要将其留空,请指定一个值属性的空字符串,或将属性全部保留。

<label for="textField">A text input field</label> 
<input type="text" name="textField" id="textField" value="" /> 

实施例1

以下代码用于index.htm文件,它有一个文本字段和提交按钮。

<html>
<body>
   <form action="index.php" method="get">
      <input type="text" name="user" />
      <input type="submit" value="hit it!" />
    </form>
</body>
</html>

将以下脚本命名为 index.php ,并将其放在同一个文件夹中上面的 index.htm 文件。 它通过使用从文本字段接受值字段名称 user


<?php
  print "Welcome <b>" . $_GET ["user"] . "</b><br/>";
?>


实施例2

一个PHP号码猜测脚本


<?php// ww  w .jav a  2s  .  c o m
$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!";
}
?>
<html>
<body>
  <h1> 
     <?php print $message ?> 
  </h1>
  <form method="post" action="<?php print $_SERVER["PHP_SELF"]?>">
  <p>
     Type your guess here: 
     <input type="text" name="guess" />
     <input type="submit" value="submit" />
  </p>
  </form>
</body>
</html>


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号