Analyze the specific implementation method of feedback form in PHP_PHP tutorial

WBOY
Release: 2016-07-15 13:29:57
Original
1037 people have browsed it

A website often has functions such as filling out forms for user registration. It is very simple for us to obtain form data through PHP. When a form is sent, each element contained in the form is assigned a corresponding value, and can be used like a reference to a general variable.

<ol class="dp-xml">
<li class="alt">
<span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>FORM</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"myform"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>ACTION</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"process_form.php3"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>METHOD</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"POST"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong></span><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>INPUT</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>TYPE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"TEXT"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>NAME</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"mytext"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>VALUE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Some Value"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>FORM</SPAN><SPAN class=tag>></span></font></strong><span> </span>
</li>
</ol>
Copy after login

In process_form.php3, the variable $mytext is assigned the entered value - very simple! Similarly, you can get variable values ​​from form elements such as list boxes, multi-select boxes, radio boxes, buttons, etc. The only thing you have to do is give each element in the form a name so that you can reference it later.

According to this feedback form method in PHP, we can generate a simple form containing three elements: name, e-mail address and message. When the visitor sends the form, the PHP page (sendfdbk.php3) that processes the form reads the data, checks whether the name is empty, and finally emails the data to you.

Form: form.php3

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"><?</FONT></STRONG></SPAN><SPAN>   </SPAN></SPAN><LI class=""><SPAN></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>include</FONT></STRONG></SPAN><SPAN>("include/common.inc");   </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>title</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Feedback"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=""><SPAN>include("include/header.inc");   </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></font></strong></span><span>   </span></span></li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>P</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>FORM</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>ACTION</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"sendfdbk.php3"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>METHOD</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"POST"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>INPUT</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>TYPE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"text"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>NAME</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"name"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Your name"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>SIZE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"20"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>MAXLENGTH</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"30"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>INPUT</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>TYPE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"text"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>MAXLENGTH</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"40"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>WIDTH</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"20"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>value</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Your Email"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>NAME</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"email"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>BR</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>TEXTAREA</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>ROWS</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"7"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>COLS</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"40"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>NAME</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"comment"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>   </span>
</li>
<li class=""><span>Your feedback on my home page.   </span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>TEXTAREA</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>BR</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>INPUT</SPAN></FONT></STRONG><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>TYPE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"submit"</FONT></SPAN><SPAN> </SPAN><SPAN class=attribute><FONT color=#ff0000>VALUE</FONT></SPAN><SPAN>=</SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Send Feedback!"</FONT></SPAN><SPAN class=tag><STRONG><FONT color=#006699>></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>FORM</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>P</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699"><?</FONT></STRONG></SPAN><SPAN>   </SPAN></SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>include</FONT></STRONG></SPAN><SPAN>("include/footer.inc");   </SPAN></SPAN><LI class=""><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></font></strong></span><span>   </span>
</li>
</ol>
Copy after login

Feedback form processing form in PHP: sendfdbk .php3

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><strong><font color="#006699"><?</FONT></STRONG></SPAN><SPAN>   </SPAN></SPAN><LI class=""><SPAN></SPAN><SPAN class=tag-name><STRONG><FONT color=#006699>include</FONT></STRONG></SPAN><SPAN>("include/common.inc");   </SPAN></SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>title</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>"Feedback"</FONT></SPAN><SPAN>;   </SPAN></SPAN><LI class=""><SPAN>include("include/header.inc");   </SPAN><LI class=alt><SPAN>if ( $</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> == "" )   </SPAN></SPAN><LI class=""><SPAN>{   </SPAN><LI class=alt><SPAN>// 现在我很讨厌匿名的留言!   </SPAN><LI class=""><SPAN>echo "Duh ? How come you are anonymous?";   </SPAN><LI class=alt><SPAN>}   </SPAN><LI class=""><SPAN>elseif ($</SPAN><SPAN class=attribute><FONT color=#ff0000>name</FONT></SPAN><SPAN> == "Your name")   </SPAN></SPAN><LI class=alt><SPAN>{   </SPAN><LI class=""><SPAN>// 这个浏览者真是不想透露姓名啊!   </SPAN><LI class=alt><SPAN>echo "Hello ? </SPAN><STRONG><FONT color=#006699><SPAN class=tag><</SPAN><SPAN class=tag-name>B</SPAN><SPAN class=tag>></font></strong></span><span>Your name</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>B</SPAN><SPAN class=tag>></span></font></strong><span> is supposed to be replaced with   </span></span></li>
<li class="">
<span>your actual name!</span><strong><font color="#006699"><span class="tag"></</SPAN><SPAN class=tag-name>B</SPAN><SPAN class=tag>></span></font></strong><span>";   </span>
</li>
<li class="alt"><span>}   </span></li>
<li class=""><span>else   </span></li>
<li class="alt"><span>{   </span></li>
<li class=""><span>// 输出一段礼貌的感谢语   </span></li>
<li class="alt"><span>echo "   </span></li>
<li class=""><span>Hello, $name.   </span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>BR</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class=""><span>Thank you for your feedback. It is greatly appreciated.   </span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>BR</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class=""><span>Thanking you   </span></li>
<li class="alt">
<span></span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>BR</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="">
<span>$MyName </span><strong><font color="#006699"><span class="tag"><</SPAN><SPAN class=tag-name>BR</SPAN><SPAN class=tag>></span></font></strong><span>   </span>
</li>
<li class="alt"><span>$MyEmailLink   </span></li>
<li class=""><span>";   </span></li>
<li class="alt"><span>// 最后mail出去   </span></li>
<li class=""><span>mail($MyEmail, "Feedback.","   </span></li>
<li class="alt"><span>Name : $name   </span></li>
<li class=""><span>E-mail : $email   </span></li>
<li class="alt"><span>Comment : $comment   </span></li>
<li class=""><span>");   </span></li>
<li class="alt"><span>}   </span></li>
<li class=""><span>include("include/footer.inc");   </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span>   </span>
</li>
</ol>
Copy after login

The above code is the feedback form in PHP All implementation methods.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446343.htmlTechArticleA website often has functions such as filling out forms for user registration. It is very simple for us to obtain form data through PHP. When a form is sent, the information contained in the form...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template