HTML Forms

Forms Template Demo

The HTML form below is part of our form template zip kit. Take it for a test drive then download the zip file if you want to examine it further.

HTML Form Template Kit

The form template kit includes extra background images for changing the color of the header. It includes the HTML form and 2 scripts for processing the data. The first script allows the user to make adjustments to the data entered. It also verifies for empty or incorrect field data entries. The second script saves the data in a file and returns a thank you message to the user. A mini tutorial for making modifications is also included. We recommend the use of a localhost server for testing on your PC.
Download Form_Template_ Kit.zip

HTML Forms and CGI

HTML forms are used in the development of interactive website design. Information is entered in text boxes. The Submit button (Next) is pressed and a CGI script processes the data.

Forms can be built using HTML , PERL and now PHP. At the present time most CGI scripts are written in PHP. Once the script is built it can be uploaded to your web space for testing.

A better way to test forms and CGI scripts is to set up a localhost server on your PC. The most popular server for this task is the Apache Server. If CGI scripts are written in Perl or PHP, they must also be installed and coordinated with the localhost server.

HTMLPad 2010 a Must Have for Writing Scripts

HTMLPad 2010If you get tired of creating forms and the scripts to process them, uploading them to your server only to find they don't work, making changes and re-uploading until you finally get it right, THERE'S A BETTER WAY!!

Set up the localhost server mentioned above and get a copy of HTMLPad 2010. It only takes a few seconds to set it up to work with your localhost.

Create and debug your forms and scripts before you upload them.
See my tutorial on Setting up a localhost and HTMLPad 2010



 Name
 First:  Last: 

 Address
 Street:   City: 

 Zipcode:  Select State:
 (5 digits)

 Home Phone:  Work Phone: 
 (Numbers only no dashes)
 

How easy is PHP?

The data gathered from forms can be printed to the screen, emailed and saved in text files.

The first script below would collect the data entered into the form, email it to you and then print a message on the screen with a link to a designated location.

<?php
$msg = "First Name: $firstname Last Name: $lastname Street: $street City: $city State: $state Zip: $zip Work Ph: $wphone Home Ph: $hphone\n\n";
$recipient = "email address you are sending to";
$subject = "Personal Information Form";
$mailheaders = "From: one of your existing pop email adresses\n \n";
mail($recipient, $subject, $msg, $mailheaders);
PRINT "Thanks for trying our resources. <a href=personal-information-form.html>Return to form.</a>";
?>

To use this script change the strings in the first line to match those on your input form.

Plug in your email adresses

Save the script with a php extension.

Upload the form and script to your server and set file permissions to 755(CHMOD).

Note: PHP scripts are not placed in your cgi-bin folder. Place them in the same folder as your forms.

Save to a File

The PHP script below will save the contents of the form in a file named practiceFile.txt, thank the visitor and provide a link back to the form after processing. Any future entries will be appended to the bottom of the file.

<?php
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$street=$_POST['street'];
$city=$_POST['city'];
$zip=$_POST['zip'];
$state=$_POST['state'];
$hphone=$_POST['hphone'];
$wphone=$_POST['wphone'];


$myFile = "practiceFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $firstname;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);
$stringData = $lastname;
fwrite($fh, $stringData);

$stringData = "\n";
fwrite($fh, $stringData);

$stringData = $street;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);
$stringData = $city;
fwrite($fh, $stringData);

$stringData = "\n";
fwrite($fh, $stringData);

$stringData = $zip;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);
$stringData = $state;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);

$stringData = $hphone;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);
$stringData = $wphone;
fwrite($fh, $stringData);
$stringData = "\n";
fwrite($fh, $stringData);
fclose($fh);

?>
<html>
<body>
<p>Thanks Much!!</p>
<p><a href=form.html>Back to Form</a>
</body>
</html>


Copy everything including the HTML code at the bottom. Save it as save_file.php

If you want a simplified form that's set up to use the script. Click Here

Just save the form where you save the script and you're ready. If you've got your localhost and HTMLPad 2010 set up, you can test it right on your PC.

There are short cuts for writing files like this. The simplicity of this one makes the process easier to see.

There is a shorter version in the Kit. Download Form_Template_ Kit.zip