PHP Tutorial: Writing Your First PHP Script: Feedback Form Script
by Christopher Heng,
thesitewizard.com I have always believed that the most fun way to learn a new programming language, whether it is a language like C or a scripting language like PHP, is to use it to write a real-life useful program. Of course this is not the most systematic method of learning, but it works well if you already have some background in programming.
Preliminaries
Before you write your first PHP program, make sure that that your website is running on a web host that runs PHP 4.1 or above.
You may also find it useful to have a copy of PHP 4.1 or later installed on your own computer. This makes testing your PHP scripts much easier. If you use Windows, you can find some tips on installing PHP on your own computer from my article on "How to Install and Configure PHP 5 to Run with Apache on Windows" at http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
And of course, you will need an ASCII text editor of some kind (such as Notepad on Windows). There's a list of such editors on http://www.thefreecountry.com/programming/editors.shtml
This tutorial also assumes that you have at least some knowledge of HTML. This is necessary because if I have to explain all the HTML tags as well, this tutorial will end up being tediously long.
You'll probably need a bit of programming background, or at the very least, an aptitude for computer programming. Note that being able to code in HTML does not count, since HTML is not a programming language. Unlike the majority of the other articles on thesitewizard.com, this article is not targeted at the absolute newcomer. You really need background in both web design using HTML and a bit of programming skill/aptitude, otherwise this article will be indecipherable. If you are reading this article because you want to create a website, please start with How to Make / Create Your Own Website: The Beginner's A-Z Guide instead.
I will begin with a very rudimentary (but working) PHP script to take input from a feedback form and send it to you in an email message. This type of form is sometimes referred to as a FormMail or Form to Mail script. In later articles, I will develop that script (and others) to include features commonly found in such FormMail scripts.
If you are programming-savvy, you will recognize this as a sort of "Hello World" program, but infinitely more useful!
Writing the Feedback Form
The first thing we need to do is to write the feedback form itself. Put the following code in the
section of an HTML file named, say, feedback.html.
Basically the form asks the visitor for his email address (the field named "email" found in input name="email"
above) and message (the field named "message" found in textarea name="message"
), and presents him with a button which he can click to submit the contents of the form. When the form is submitted, it is "posted" (see the "method" attribute of the
No comments:
Post a Comment