PHP表單處理指南

jieforest發表於2012-06-14
One of the key things to learn if you are just starting to learn PHP is how to handle forms. This process seems to stump new developers to PHP but this shouldn’t be a big obstacle.

PHP has many features that allow for simple data gathering and easy form. processing. In this tutorial, I will discuss how to use the action method of the form. and show you how to create a simple form. that you can use on your site that will allow your visitors to contact you via email.

This will require the creation of two items: the HTML form. and the PHP script. that will handle it. The tutorial includes a snippet of PHP and HTML source code that you can use as a starter for your form.

Setting up the HTML


Here is my simple HTML contact form.:

CODE:


        Name:

        Email:

        Comments:


       
When you look at this HTML contact form. you may notice that most HTML form. elements have a name, id and value. The id attribute is not required but if you are doing any JavaScript. or have CSS styles you may need to use them. The name property is what we will use to get the values in PHP.

There are two ways to send form. data, GET and POST. For the purposes of this article, I will be sending this data via POST, as you can see in the
tag. If you would like to learn more about the differences between GET and POST, please see our article detailing the difference at length.

Our PHP script. will be named “handler.php” and it is given in the action portion of the
tag. You can name your PHP script. whatever you like, as long as you place it here so the form. knows what to do when the user hits submit.










來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-732765/,如需轉載,請註明出處,否則將追究法律責任。

相關文章