PHP combines forms to implement some simple functions examples _php tutorial

Source: Internet
Author: User
Example one (post submission form):
Copy CodeThe code is as follows:


<title><br>chunkify Form <BR></title>







Copy CodeThe code is as follows:


<title><br>chunkify Word <BR></title>

$word =$_post[' word '];
$number =$_post[' number '];
$chunks =ceil (strlen ($word)/$number);
echo "The $number-letter chunks of ' $word ' are:
\ n ";
for ($i = 0; $i < $chunks; $i + +) {
$chunk =substr ($word, $i * $number, $number);
printf ("%d:%s
\ n ", $i +1, $chunk);
}
?>



HTML Displays the page.

The page to be processed by PHP after the form is submitted. In this example, I enter a word and then, given a length, divide the word into chunks of that length.

Demonstrates submitting a form through the post method.
Example two (single radio, get accept form):
Copy CodeThe code is as follows:


if (array_key_exists (' s ', $_get)) {
$des = Implode (' ', $_get[' att ');
echo "You have a $des personality.";
}
?>


Example three (multi-select, get accept form):

Notice that at this pointUnderline tells get that you are transmitting the array, the bold part is to change the selection box to a multi boxCopy CodeThe code is as follows: if (array_key_exists (' s ', $_get)) {$des = Implode (' ', $_get[' att ');echo "You have a $des personality.";}?> Example Four (check box checkbox): The same name= "att[" is to tell get you are transmitting an array, checked means that the option is the initial default selection, the same example, adding Selected= "selected" in the tag can alsoMake multiple selections the initial default selection.Copy CodeThe code is as follows: if (array_key_exists (' s ', $_get)) {echo "";Print_r ($_get);echo "";if (Is_null ($_get[' att])) exit;$des = Implode (' ', $_get[' att ');echo "You have a $des personality.";}?> Example five (single box): Note that the same option can be a single selection must be name equalCopy CodeThe code is as follows: When a user taps a radio button, the button becomes selected and all other buttons become unchecked. Example six (stick form): How a table is to be implemented before the values entered are still present after the page is refreshed can be as followsCopy CodeThe code is as follows: $f = $_post[' fa '];?> if (!is_null ($f)) {$c = ($f-32) *5/9;printf ("%.2lf is%.2LFC", $f, $c);}?> Are some simple form processing ~Knowledge Make me stronger!Http://www.bkjia.com/PHPjc/323405.htmlWww.bkjia.comTrueHttp://www.bkjia.com/PHPjc/323405.htmlTecharticleExample one (POST submission form): Copy the Code code as follows: HTML head title chunkify Form/title/head body Form action= "chunkify.php" method= "POST" Enter A Word:input type= "Text ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.