Web Tool Bag  
Home · Articles · Downloads · Discussion Forum · Web Links · News Categories · Synonyms DatabaseJuly 18 2024 04:48:25
Discussion Forum
Web Links
News Categories
Synonyms Database
Users Online
Guests Online: 1
No Members Online

Registered Members: 856
Unactivated Members: 118
Newest Member: lakim
Forum Threads
Newest Threads
Error: Cannot find m...
Uncaught Error: _reg...
Module build failed:...
mochi script questions
Hottest Threads
Installation [12]
Any questions and... [5]
Captcha picture d... [4]
Integrate with Vi... [4]
Mods: Sucess/Than... [4]
Latest Articles
Ubuntu: the vpn conn...
Howto Install HP Pri...
ReactJS progress met...
Create a Simple, Effective PHP Form for Your Web Site

Create a Simple, Effective PHP Form for Your Web Site

by Herman Drost

If you have been struggling to set up forms on your web site using cgi, then definitely read this article. Installing a simple PHP form is much easier and faster than installing a cgi form and doesn't need any programming experience.

How does a PHP form work?

PHP is short for "PHP: Hypertext Preprocessor". It is a server-side, cross-platform, HTML embedded scripting language.

A server side scripting language allows you to create dynamic web pages. Web pages that have been enabled with PHP are treated just the same as any other HTML page, and PHP even lets you create and edit them the same way you would create and edit your HTML pages.

This PHP form consists of 3 web pages, an html page, a PHP page (PHP script) and a thank you page. You collect the visitors information when he fills out the form on the html page. It is then processed by the PHP script which resides on the server. The visitor automatically receives a "thank you for subscribing" message. The form results are returned from the server to your email box.

Server requirements for your PHP form

Check with your web host you have PHP4 installed on your server Most Unix servers do - if so you are in luck and ready to go.

How to create the simple PHP form

You will create a very simple, effective form in which you will collect the name, email address and comments of your visitors. The form results will be sent to your email address.

1. Create the PHP script - copy and paste this code (Jack's FormMail.php script: http://www.dtheatre.com/scripts/formmail) into notepad (not MS Word) and save it as formmail.php

2. Edit the fields - the only recommended field to edit is the "referers" field. This field defines the domains that allow forms to reside on and use your FormMail.php script. If you try to put the form on another server, that is not the specified domain or ip, you will receive an error message when someone tries to fill out your form.

ie: $referers = ('ihost-websites.com','');

3. Upload the formmail.php script to the web directory which you are planning to use.

4. Configure your PHP form - create a web page (ie contact.htm) for your PHP form.

5. Point the action of your form to the formmail.php script you created in Step 1.

ie: <form name="form1" method="post" action="http://www.ihost-websites.com/formmail.php">

6. Add the necessary form fields - the "recipient field" is the only form field that you must have in your form, for formmail.php to work correctly.

This form field allows you to specify where you want your form results to be mailed. Most likely you will want to configure this option as a hidden form field with a value equal to that of your e-mail address.

<input type=hidden name="recipient" value="info@ihost-websites.com">

7. Enter optional form fields

"subject field" - this allows you to specify the subject that you wish to appear in the e-mail that is sent to you after this form has been filled out. If you do not have this option turned on, then the script will default to a message subject: "Form Submission".

ie: <input type=hidden name="subject" value="Form Mail Results">

"full name field" - this allows visitors to fill in their name. This will help you to personalize your return email by including their first and/or last names.

i.e: <input type=text name="fullname">

"email address field" - this allows you to specify your return e-mail address. If you want to be able to return e-mail to your user, I strongly suggest that you include this form field and allow them to fill it in. This will be put into the From: field of the message you receive. The email address submitted will be checked for validity.

i.e: <input type=text name="email">

"comments field" - this allows visitors to add any comments in your form. You could name this field anything you like.

ie: <textarea name="comments"></textarea>

"required field" - these are the required fields you want your visitors to fill in before they can successfully submit the form. If the required fields are not filled in, the visitor will be notified of what they need to fill in, and a link back to the form they just submitted will be provided.

ie: <input type=hidden name="required" value="fullname,email">

"redirect field" - if you wish to redirect the visitor to a different URL, rather than having them see the default response to the fill-out form, you can use this hidden variable to send them to a pre-made HTML (ie thankyou.htm) page.

ie: <input type=hidden name="redirect" value="http://www.ihost-websites.com/thankyou.htm">

"submit field" - this allows the visitor to submit the form

ie: <input type="submit" name="Submit" value="Submit">

8. Create a thank you page (thankyou.htm) - this web page will automatically thank visitors for subscribing. Add your own comments you wish them to receive. Upload this web page to your server.

Tip: Use your own domain name, email and IP address in the fields above.

Here is an example of a typical web page using the PHP form. (http://www.ihost-websites.com/contact.htm)

All the fields are included as was discussed above:

<html> <head> <title>Form Mail</title> </head>

<body bgcolor="#FFFFFF" text="#000000"> <form name="form1" method="post" action="http://ihost-websites.com/formmail.php">

<input type=hidden name="recipient" value="info@ihost-websites.com">

<input type=hidden name="subject" value="Form Mail Results">

<input type=hidden name="required" value="fullname,email">

<input type=hidden name="redirect" value="http://www.ihost-websites.com/thankyou.htm">

Name<br><input type=text name="fullname"><br>

Email<br> <input type=text name="email"><br>

<br> Comments<br> <textarea name="comments"></textarea> <br>

<br> <input type="submit" name="Submit" value="Submit">


</body> </html>

9. Copy and paste this html form into your web page - name it anything you like (ie contact.htm), then upload it to your server.

10. Test out your form - when you fill out the form, you should immediately receive the reply from your thankyou.htm page and receive the form results in your email box.

Conclusion - you now have a fully functional and flexible PHP form on your web site to collect visitor information. You can add more fields to the form if necessary. You may also add any number of HTML forms to your web site and still use the same PHP script.


Posted by admin on December 03 2006 12:24:43 13980 Reads · Print
Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.


Not a member yet?
Click here to register.

Forgotten your password?
Request a new one here.
Member Poll
Which PHP framework do you preffer?





eZ Components






You must login to vote.
You must login to post a message.

03/10/2011 18:17
Hi, How to remove Register from Login screen? I don't want them to register and have full access! if you leave register then they should not have any rights until the admin assigns them

26/09/2011 08:28
Please describe your problem with more details. Thank you.

22/11/2010 18:31
Help. There was a problem with the request; error regarding feedbackzdr form program

Custom web software development by Devzone Tech
Copyright © 2024 - www.webtoolbag.com