PHP/Form/TextBox

Материал из Web эксперт
Версия от 07:04, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

A PHP Number-Guessing Script

 
<?php
$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>
<head>
<title>A PHP Number Guessing Script</title>
</head>
<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>



Disable TextBox

<!-- Save as CallMySelfPHP.php -->
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="CallMySelfPHP.php">
    <TABLE>
    
    <TR>
    <TD><INPUT TYPE="TEXT" NAME="OP1" 
      VALUE="<? echo  $OP1 ?>"></TD>
    </TR>
    
    <TR>
    <TD ALIGN="CENTER">+</TD>
    </TR>
    
    <TR>
    <TD><INPUT TYPE="TEXT" NAME="OP2" 
      VALUE="<? echo  $OP2 ?>"></TD>
    </TR>
    
    <TR>
    <TD ALIGN="CENTER"><INPUT TYPE="SUBMIT" VALUE="="></TD>
    </TR>
    
    <TR>
    <TD><INPUT TYPE="TEXT" NAME="RESULT" 
      VALUE ="<? echo  $OP1 + $OP2 ?>"
      disabled></TD>
    </TR>
    
    </TABLE>
</FORM>
</BODY>
</HTML>



Form Numeric value

<HTML>
<BODY>
<FORM METHOD="POST" ACTION="FormNumericValue.php">
   Enter a numeric value:
  <BR>
  <INPUT TYPE="TEXT" NAME="number">
</FORM>
</BODY>
</HTML>

<!-- FormNumericValue.php
<HTML>
<BODY>
<?php
  echo "The number entered was: $number.";
  if ($number > 10)
      echo "<BR>That"s a big number.";
?>
</BODY>
</HTML>
-->



Get Text Field value

<HTML>
<BODY>
<FORM METHOD="POST" ACTION="TextFieldValue.php">
    <TABLE>
    
    <TR>
    <TD ALIGN="RIGHT">User"s First Name:</TD>
    <TD><INPUT TYPE="TEXT" NAME="USER"></TD>
    </TR>
    
    <TR>
    <TD ALIGN="RIGHT">Major City:</TD>
    <TD><INPUT TYPE="TEXT" NAME="CITY"></TD>
    </TR>
    
    <TR>
    <TD ALIGN="RIGHT">Favorite Ice Cream Flavor:</TD>
    <TD><INPUT TYPE="TEXT" NAME="FLAVOR"></TD>
    </TR>
    
    <TR>
    <TD ALIGN="RIGHT">Favorite Pop Music Star:</TD>
    <TD><INPUT TYPE="TEXT" NAME="STAR"></TD>
    </TR>
    
    <TR>
    <TD ALIGN="RIGHT">Name of Famous River:</TD>
    <TD><INPUT TYPE="TEXT" NAME="RIVER"></TD>
    </TR>
    
    <TR>
    <TD></TD>
    <TD><INPUT TYPE="SUBMIT"></TD>
    </TR>
    
    </TABLE>
</FORM>
</BODY>
</HTML>
<!-- TextFieldValue.php
<HTML>
<BODY>
<CENTER><?php echo date("l, F j, Y") ?></CENTER>
<HR>
<?php echo $CITY ?>:
<P>
<?php echo $STAR ?>    <br>
<?php echo $FLAVOR ?>  <br>
<?php echo $RIVER ?>   <br>
<?php echo $CITY ?>    <br>
<?php echo $USER ?>    <br>
</BODY>
</HTML>
-->