PHP/Form/ GET

Материал из Web эксперт
Перейти к: навигация, поиск

Properly Checking for Submission Using Image Widgets

   <source lang="html4strict">

<INPUT TYPE="image" NAME="submit_one" SRC="b.gif"> <INPUT TYPE="image" NAME="submit_two" SRC="b2.gif">

//Properly determining which submission button was clicked in PHP: <?php

    if(isset($_GET["submit_one_x"])) {
    } elseif(isset($_GET["submit_two_x"])) {
    } else {
    }

?>

 </source>
   
  


Reading Input from the Form

   <source lang="html4strict">

<html> <head> <title>A Simple HTML Form</title> </head> <body>

<form action="index.php" method="get">

<input type="text" name="user" />

<textarea name="address" rows="5" cols="40"> </textarea>

<input type="submit" value="hit it!" />

</form>

</body> </html>

// index.php <html> <body>

<?php
 print "Welcome " . $_GET ["user"] . "
\n\n"; print "Your address is:
" . $_GET ["address"] . "";  ?>

</body> </html>

 </source>
   
  


Time-Sensitive Form Example

   <source lang="html4strict">

<? <FORM ACTION="index.php" METHOD=GET> <INPUT TYPE="hidden" NAME="time" VALUE="<?php echo time(); ?>"> Enter your message (5 minute time limit):<INPUT TYPE="text" NAME="mytext" VALUE=""> <INPUT TYPE="submit" Value="Send Data"> </FORM> if($_GET["time"]+300 >= time()) {

    echo "You took too long!
"; exit;

} ?>

 </source>
   
  


Using Arrays with Form Data in PHP

   <source lang="html4strict">

<SELECT NAME="myselect[]" MULTIPLE SIZE=3> <OPTION VALUE="value1">A</OPTION> <OPTION VALUE="value2">B</OPTION> <OPTION VALUE="value3">C</OPTION> <OPTION VALUE="value4">D</OPTION> </SELECT>

//The PHP code to access which value(s) were selected: <?php

    foreach($_GET["myselect"] as $val) {
         echo "You selected: $val
"; } echo "You selected ".count($_GET["myselect"])." Values.";

?>

 </source>