PHP/Form/ GET
Версия от 10:37, 26 мая 2010; (обсуждение)
Содержание
Properly Checking for Submission Using Image Widgets
<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 {
}
?>
Reading Input from the Form
<html>
<head>
<title>A Simple HTML Form</title>
</head>
<body>
<div>
<form action="index.php" method="get">
<p><input type="text" name="user" /></p>
<p><textarea name="address" rows="5" cols="40">
</textarea></p>
<p><input type="submit" value="hit it!" /></p>
</form>
</div>
</body>
</html>
// index.php
<html>
<body>
<div>
<?php
print "Welcome <b>" . $_GET ["user"] . "</b><br/>\n\n";
print "Your address is: <br/><b>" . $_GET ["address"] . "</b>";
?>
</div>
</body>
</html>
Time-Sensitive Form Example
<?
<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!<BR>";
exit;
}
?>
Using Arrays with Form Data in PHP
<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<BR>";
}
echo "You selected ".count($_GET["myselect"])." Values.";
?>