Home > Backend Development > PHP Tutorial > Examples of php combining forms to implement some simple functions_PHP tutorial

Examples of php combining forms to implement some simple functions_PHP tutorial

WBOY
Release: 2016-07-21 15:29:29
Original
786 people have browsed it

例子一(POST提交表单):

复制代码 代码如下:



<br>Chunkify Form <br>



Enter a word:


How long should be the chunks be?








复制代码 代码如下:



<br>Chunkify Word <br>

$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);
}
?>



Examples of php combining forms to implement some simple functions_PHP tutorial

html显示出来的页面。

Examples of php combining forms to implement some simple functions_PHP tutorial

提交表单后php处理出来的页面。在这个例子中,我输入一个单词,然后给定一个长度,将单词等分成该长度的块。

演示了通过POST方法提交表单。
例子二(单选,GET接受表单):

复制代码 代码如下:


Select your personality attributes:







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

Examples of php combining forms to implement some simple functions_PHP tutorial
例子三(多选,GET接受表单):

注意到此时












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

Examples of php combining forms to implement some simple functions_PHP tutorial
Example 4 (checkbox): Similarly name="att[]" tells GET that what you transmit is an array, checked means that the option is the initial default Selection, the same as the above example, adding selected="selected" in the tag can also

make the initial default selection for multiple selections.
Copy code The code is as follows:


Select your personality attributes:

perky

morose

thinking

feeling < ;br/>





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.";
}
?>

Examples of php combining forms to implement some simple functions_PHP tutorial
Example 5 (radio button): Note that the same option can be used The selected names must be equal
Copy code The code is as follows:


Male:
< input type="radio" checked="checked" name="Sex" value="male" />


Female:





Male:



Female:


When the user clicks a radio button, the button becomes selected and all other buttons become unselected.



Examples of php combining forms to implement some simple functions_PHP tutorial
Example 6 (stick form): How can a form realize that the previously entered values ​​still exist after the page is refreshed? As follows
Copy the code The code is as follows:

$f = $_POST['fa'] ;

?>


temperature :
;


< input type="submit" name="Convert to Celsius" />

if (!is_null($f)){
$c = ($f-32)*5/9;
printf("%.2lf is %.2lfC",$f,$c);
}
?>

Examples of php combining forms to implement some simple functions_PHP tutorial

Examples of php combining forms to implement some simple functions_PHP tutorial

It’s all simple form processing~

Knowledge make me stronger!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323405.htmlTechArticleExample 1 (POST submission form): Copy the code as follows: html head title Chunkify Form /title /head body form action="chunkify.php" method="POST" Enter a word: input type="text...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template