Example one (post submission form):
Copy Code code as follows:
<title>
Chunkify Form
</title>
<body>
<form action= "chunkify.php" method= "POST" >
Enter a word:
<input type= "text" name= "word"/><br/>
How long should is the chunks be?
<input type= "text" name= "number"/><br/>
<input type= "Submit" value= "Chunkify" >
</form>
</body>
Copy Code code as follows:
<title>
Chunkify Word
</title>
<?php
$word =$_post[' word '];
$number =$_post[' number '];
$chunks =ceil (strlen ($word)/$number);
echo "The $number-letter chunks of ' $word ' are:<br/>\n ';
for ($i = 0; $i < $chunks; $i + +) {
$chunk =substr ($word, $i * $number, $number);
printf ("%d:%s<br/>\n", $i +1, $chunk);
}
?>
</body>
HTML to display the page.
A page that is processed by PHP after submitting a form. In this example, I type a word, then give a length, and divide the word into blocks of that length.
Demonstrates submitting a form by post method.
Example two (radio, get receive form):
Copy Code code as follows:
<form action= "<?php echo $_server[' php_self ']?>" method= "Get" >
Select your personality attributes:<br/>
<select name= "att[]" >
<option value= "Perky" >perky</option>
<option value= "Morese" >morose</option>
<option value= "thinking" >thinking</option>
<option value= "Feeling" > feeling</option>
<option value= "Thrifty" >speed-thrift</option>
<option value= "Prodigal" >shopper</option>
</select>
<br>
<input type = "Submit" Name= "S" value= "record my Personality" >
</form>
<?php
if (array_key_exists (' s ', $_get)) {
$des = Implode (', $_get[' att '));
echo "You have a $des personality";
}
?>
Example three (multiple selection, get accept form):
Notice that at this point <select name= "att[]" multiple> underscore tells get that you are transmitting the array, the bold character part is to change the selection box to a multiple-selection box
Copy Code code as follows:
<form action= "<?php echo $_server[' php_self ']?>" method= "Get" >
Select your personality attributes:<br/>
<select name= "att[]" multiple>
<option value= "Perky" >perky</option>
<option value= "Morese" >morose</option>
<option value= "thinking" >thinking</option>
<option value= "Feeling" > feeling</option>
<option value= "Thrifty" >speed-thrift</option>
<option value= "Prodigal" >shopper</option>
</select>
<br>
<input type = "Submit" Name= "S" value= "record my Personality" >
</form>
<?php
if (array_key_exists (' s ', $_get)) {
$des = Implode (', $_get[' att '));
echo "You have a $des personality";
}
?>
Example Four (CheckBox checkbox): The same name= "att[]" is to tell get that you are transmitting an array, checked indicates that the option is the initial default choice, and in the same example, adding Selected= "selected" to the label can also
Let the multiple-selection initial default selection.
Copy Code code as follows:
<form action= "<?php echo $_server[' php_self ']?>" method= "Get" >
Select your personality attributes:<br/>
Perky<input type= "checkbox" Name= "att[]" value= "perky" checked/> <br/>
Morose<input type= "checkbox" Name= "att[]" value= "morose" checked/> <br/>
Thinking<input type= "checkbox" Name= "att[]" value= "thinking"/> <br/>
Feeling<input type= "checkbox" Name= "att[]" value= "Feeling"/> <br/>
<br>
<input type = "Submit" Name= "S" value= "record my Personality" >
</form>
<?php
if (array_key_exists (' s ', $_get)) {
echo "<pre>";
Print_r ($_get);
echo "</pre>";
if (Is_null ($_get[' att ')) exit;
$des = Implode (', $_get[' att '));
echo "You have a $des personality";
}
?>
Example five (radio box): Note that a single selection with the same option must have the name equal
Copy Code code as follows:
<form>
Men:
<input type= "Radio" checked= "Checked" name= "Sex" value= "male"/>
<br/>
Women:
<input type= "Radio" name= "Sex" value= "female"/>
<br>
Men:
<input type= "Radio" checked= "Checked" name= "Se" value= "male"/>
<br/>
Women:
<input type= "Radio" name= "Se" value= "female"/>
</form>
<p> When a user clicks a radio button, the button becomes selected and all other buttons become unselected. </p>
Example six (stick form): how a table can be implemented before a page refresh will still exist as follows
Copy Code code as follows:
<?php
$f = $_post[' fa '];
?>
<form action = "<?php echo $_server[' php_self ';?>" method= "POST" >
Temperature:
<input type= "text" name= "fa" value= "<?php echo $f;? > "/>;
<br/>
<input type= "Submit" Name= "Convert to Celsius"/>
</form>
<?php
if (!is_null ($f)) {
$c = ($f-32) *5/9;
printf ("%.2lf is%.2LFC", $f, $c);
}
?>
Are some simple forms to deal with ~
Knowledge Make me stronger!