CSVwrite - Write to a database from a web form
Send information to a database from a web-based form. The script is very simple to set-up and customize using the look and feel of your own website. The advanced version can send a copy of the data to the webmaster, and can require input for up to three types of fields. The data is stored as a CSV database. (CGI/Perl Unix)

» Overview of the script
» Set-up the script basic version
» Set-up the script Xtra version
» Create your database
» Create the form on your website
» Create the Thank You page



CSVwrite:
From a simple or complicated form on your website the data is sent to the CSVwrite script. This then adds the information to the database and sends the visitor to a new web page.

CSVwrite Xtra:
From a simple or complicated form on your website the data is sent to the CSVwrite script. This then checks the data and adds the information to the database and sends the visitor to a new web page, or displays the data sent using CSVread. A copy of the data is sent to the webmaster.

Files you will need:
•  CSVwrite script (download from this website)
•  Webpage with a form (instructions on this page)
•  Database (instructions on this page)
•  Thank you page (any standard web page)

Things you have to do:
Follow the instructions below Download the CSVwrite script and make a few changes Create a form on your website Create a database (or let CSVwrite do it!) Create a 'thank you' page Upload the script and webpages.

Minimum Requirements:
•  Your own website with FTP access
•  Permission to run CGI scripts on your server
•  UNIX web hosting with Perl 5.006001 or greater
•  Sendmail or access to SMTP (Xtra Version)

Features Basic Xtra
For commercial and private use YES YES
Can be used on as many websites as I build YES YES
No adverts or links in the script YES YES
Instant download YES YES
Write data from any web form with CGI YES YES
Hide the database location from web users YES YES
Redirect users to any web page after sending data YES YES
Script can create the database on first YES YES
Manage line breaks into HTML or spaces YES YES
Send the data by email using sendmail or SMTP - YES
Required fields option for numbers only - YES
Required fields option for Email address only - YES
Required fields option for general text - YES
Write the users IP address to the database - YES
Write the users Browser details to the database - YES
Write the server date and time to the database - YES
Option to change the delimiter - YES
Option to change the character replacing delimiter - YES
Option to allow or block HTML code - YES
Use image as 'GO' button rather than HTML - YES
Write a number ID to the database YES YES
Send field name and data or just data by email - YES
Use the one script to write to different databases - YES
Send an auto responder to the visitor - YES
Display submitted data rather than generic thank you page - YES
File upload with form (not possible on all web servers) - YES
Show field values from form on a Thank You page - YES
Use HTML includes in Thank You page - YES
Use a different administrator mail address per database - YES
Filter to block 'bad' words - YES

Back to top


Set-up the script basic version

Check your path to perl
#!/usr/bin/perl

Change the PATH of your database, the first time the script is run it will create the database for you. On most server you can use just the file name.
$base_file = '/path/to/your/database.txt';

Change the URL of your thank you file (This MUST be in a public directory).
$HTML_thankyou = 'http://www.your-url.co.uk/thankyou.htm';

If you are using scrolling text boxes the script will need to remove any line breaks. This is then replaced with the HTML code for a line break, or you may wish to use a space rather than the HTML code in your database.
$line_break = '<br>';

Advanced Settings auto ID

If you would like CSVwrite to automatically write an ID number for each record then change this to 1. This can then be used with the other CSV scripts.
my $ID_autoincrement = 0;

Name the field you would like the script to write the ID number to.
my $ID_autoincrement_name = "ID";

Upload and CHMOD 755, or 777 if not public.

Back to top


Set-up the script Xtra version

Check your path to perl
#!/usr/bin/perl

Change the PATH of your database, the first time the script is run it will create the database for you. On most server you can use just the file name.
my $base_file = '/path/to/your/database.txt';

Change the URL of your thank you file (This MUST be in a public directory).
my $HTML_thankyou = 'http://www.your-url.co.uk/thankyou.html';

If you are using scrolling text boxes the script will need to remove any line breaks. This is then replaced with the HTML code for a line break, or you may wish to use a space rather than the HTML code in your database.
my $line_break = '<br>';

To stop users posting HTML set this to 1, or 0 to allow HTML.
my $kill_html_tags = 1;

If you want to use an image rather than the HTML send button change this to 0 to allow an image or 1 not to allow the image button.
my $kill_image_buttons_value = 1;

If you wish to use a different delimiter in the database to the pipe you can change it. However the pipe is the standard for web database scripts.
my $separator = '|';

If you wish to change the character the script uses when a user inputs data with the delimiter. In this example we change the pipe for the letter I.
my $change = "I";

If you wish to write the users IP address, Browser information and the Date to your database you can by changing the '0' to '1'. The first time CSVwrite is used it will create the database and add the fields. If you are creating your own database you will need to add the fields.
|REMOTE_ADDR|HTTP_USER_AGENT|DATE
my $REMOTE_ADDR = 0;
my $HTTP_USER_AGENT = 0;
my $DATE = 1;

You can display the data sent by the script using CSVread/CSVsearch rather than the 'thank you' page. This feature is a little complicated. You will need to be using the 'Unique ID' feature with CSVwrite and CSVread or CSVsearch. Set the 'thank you' page to the URL of your CSVread or CSVsearch script. and then the setting below to '1' the Write script will then open the CSVread or CSVsearch script at the right 'Unique ID'. 1=on 0=off.
my $display_data_afterSubmit = 0;

Advanced Settings Thank You Page

If you use a static html 'Thank You' page, you can also let it show the values of the fields from your form. If set to 1, you can include tags like [[fieldname]] in your Thank You page, which the script will change into the value of field 'fieldname', allowing you to customize your page to the specific visitor.
$display_data_on_thankyou = 0;

Note that if you switch on this feature, $HTML_thankyou (see earlier) has to be the PATH to your 'Thank You' html page.

Advanced Settings auto ID

If you would like CSVwrite to automatically write an ID number for each record then change this to 1. This can then be used with the other CSV scripts. 1=on 0=off.
my $ID_autoincrement = 0;

Name the field you would like the script to write the ID number to.
my $ID_autoincrement_name = "ID";

Advanced Settings email

Advanced Settings if you wish to get a copy of the data by email. This feature requires sendmail or SMTP to be available on your server, check this first with your host. Most servers offer this service, however some servers do not.

Set this to '1' to send a copy of the data or to '0' not to.
my $send_me = 0;

The email address to send a copy of the data to (excluding any uploaded files).
my $admin_mail = 'email@your-url.co.uk';

Change this to the default email address you want the email to be from.
my $from = 'Nobody@your-url.co.uk';

To have the 'from email' use a value of a field in the form, then change this to the field name that will have that value.
my $from_field_name = 'fromfieldname';

The error seen if potentially damaging code is attempted to be sent.
my $email_input_error = "Non resolved email input";

Set this to 1 if you want just data by email and not the field names.
my $send_just_data = 0;

This is the PATH to your send mail (check this with your administrator).
my $mailprog = '/usr/sbin/sendmail';

The subject line in the email message.
my $subject = 'New entry in database';

If you want to see only the form fields for which a value has been filled in, then set this to 1.
my $only_fields_with_values = 0;

Advanced Settings Auto Responder

If you have set the 'from' field to be a required email address then you can send a text auto responder to the user. Change the '0' to '1' to switch on this feature and set the subject, plus the full PATH to the text file to send as the message to user.
my $auto_responder = '0';
my $auto_responder_subject = "Thank you for your form submit";
my $auto_responder_message = 'reply.txt';

Advanced Settings required SMTP rather than Sendmail

To use SMTP rather than sendmail remove the hash and space.
# use Net::SMTP;

If you wish to use SMTP rather than SENDMAIL set this to '1'.
my $send_via_SMTP = 0;

Your SMTP server details (check this with your administrator).
my $mailhost = 'smtp.com';

Advanced Settings required fields

Required fields must have no spaces or special characters in the field name.

If you set this to 1, then you can specify the required fields from your form instead of via the three script options underneath (see further down the page on how to do this from your form).
my $required_fields_form = 0;

ALL fields required with any data. Leave as () if none are required. (Ensure they are the same name as your form and database).
my @required_fields = ("fieldname","fieldname","fieldname");

The fields required with numbers. Leave as () if none are required. (Ensure they are the same name as your form and database).
my @required_fields_numbers = ("fieldname","fieldname");

The fields required with an email address. Leave as () if none are required. (Ensure they are the same name as your form and database).
my @required_fields_email = ("fieldname","fieldname");

Advanced Settings required fields errors

You can customize the error message and format a customer will see if they do not input your required fields. You can add HTML but do not any quote marks.
my $error_fields_require = "Field is blank, it is required";
my $error_fields_numbers = "Only numbers";
my $error_fields_email = "email address is not valid";
my $error_title = "<b>Sorry, we require more information</b>";
my $fontColor = "black";
my $fontSize = 3;
my $fontFace = "Verdana";
my $return_message = "Please click 'back' on your browser";

Advanced Settings extra database & 'thank you' page

If you want to use the same script but use a different database or thank you page you can. You put the location of the files in the script rather than in your form. You can have as many or few as you like.
my $field_name_database = 'mydatabase';
$DB{'db1'} = '/path/to/database1.txt';
$DB{'db2'} = '/path/to/database2.txt';
$DB{'db3'} = '/path/to/database3.txt';
$DB{'db4'} = '/path/to/database4.txt';
$DB{'db5'} = '/path/to/database5.txt';

This means that you can control which database should be selected, by entering a hidden (or not hidden) field 'mydatabase' in your form, like:
<input type="hidden" name="mydatabase" value="db2">

A nearly identical mechanism exists for the thank you pages:
my $HTML_thankyou_field_name = 'mythankyou';
$ThankYou{'tu1'} = 'http://www.your-url.co.uk/thankyou1.htm';
$ThankYou{'tu2'} = 'http://www.your-url.co.uk/thankyou2.htm';
$ThankYou{'tu3'} = 'http://www.your-url.co.uk/thankyou3.htm';
$ThankYou{'tu4'} = 'http://www.your-url.co.uk/thankyou4.htm';
$ThankYou{'tu5'} = 'http://www.your-url.co.uk/thankyou5.htm';

And again your form could then have a field like:
<input type="hidden" name="mythankyou" value="tu3">

Advanced Settings extra admin mail addresses

If you use multiple databases (Advanced Settings extra database), you might want to have an administrator mail address per database. Set this option to 1 to active this.
my $use_address_per_db = 0;

Then you can specify the mail address of the administrator for each database:
$ADDR{'db1'} = 'email@your-url.co.uk';
$ADDR{'db2'} = 'email@your-url.co.uk';
$ADDR{'db3'} = 'email@your-url.co.uk';
$ADDR{'db4'} = 'email@your-url.co.uk';
$ADDR{'db5'} = 'email@your-url.co.uk';

Advanced Settings file upload

Most web hosting will block this feature for security reasons. Check with your host that you can use file upload from a form before using this feature.

The fields in your database that will have files to upload.
my @file_upload_fields = ("fieldname","fieldname");

If you want the script to re-name the file. Strongly recommended security feature.
my $rename_file = 1;

The maximum size of file allowed.
my $max_size = 100000;

Types of files allowed. Do not allow .exe files on your server, don't leave this blank.
my @required_file_types = ("txt", "jpg", "jpeg", "tif", "gif");

Errors for wrong file type and files too large.
my $error_max_size = "Your file is too big!";
my $error_file_type = "File type is not valid!";

The PATH not URL to the folder to take the files. Your host may block all or some folders from taking files.
my $file_dir = "/home/path/to/your/file/folder/";

Enter the full URL to the folder to take the files.
my $file_URL = "http://www.your-url.co.uk/file/folder";

File size is set to bytes, to set to KB change 0 to 1.
my $useKb = 0;

Advanced Settings - Bad Words

Filter If you want to prevent visitors from using certain words in your forms, you should enable this option by setting it to 1:
my $use_filter = 0;

Then specify the PATH to a file in which you typed the 'forbidden' words (one at each line):
my $badwordsfile = 'badwords.txt';

If a bad word is found, it will be replaced by:
my $censored = '***';

Advanced Settings Include

Pages If you have $display_data_on_thankyou set to 1, then the Thank You page is being handled by the script and not the server. Any SSI includes on the page will no longer work. In order to help mitigating this, you can use script based HTML includes.

Mind you that this feature is not needed when $display_data_on_thankyou is set to 0 as you can use normal SSI includes then.

Once you set $use_includes to 1, the script will replace each occurence of [[includex]] by the corresponding HTML page/file.
my $use_includes = 0;

If you want the script to cast an error when one of the templates could not be loaded, then set this value to 1:
my $error_on_missing = 0;

You can start defining which includes the script can use:
my %INCL=();
$INCL{'include1'} = "main-menu.htm";
$INCL{'include2'} = "main-menu.htm";
$INCL{'include3'} = "main-menu.htm";
$INCL{'include4'} = "main-menu.htm";
$INCL{'include5'} = "main-menu.htm";

Upload and CHMOD 755, or 777 if not public.

Back to top


Create your database

You can create your database using notepad, but you don't need to!

The first time you run CSVwrite it will create the database for you, make sure you put some data in each field when you first run your form.

With the script you will get a sample database, you can edit this by adding new fields and records using CSVedit.

If you do create your own, don't use any special characters or spaces in the field names. Keep them short as your browser can only send a limited number of characters to the database at any one time. Ensure they match your form fields exactly. The size limitations of your database are determined by your web hosting and the server specifications.

Example database: The first line is the heading and the rest the data. You can have as many field names as you like in the database.

Your database should be less than 1000 records and under 1MB run smoothly on most shared web servers. Save your database as a plain text file database.txt See the FAQ page for excel questions.

IMPORTANT: Please do not use field names in your database used in the script or template. The following are used by the scripts and can not be used as field names name, method, action, page, record, header, random, display, search, order_by, order, mode & headlines.

Upload and CHMOD 755, or 777 if not public.

Back to top


Create the form on your website

The form action is the URL of your CSVwrite script, so each form will need to start: <form method="POST" action="/cgi-bin/csvwrite.pl">

Then end with:
<input type="submit" value=" [ CSVwrite ] ">
</form>Your fields are in the middle.

Example Code: (Ensure the field names match your database headings. Don't use any special characters or spaces in the field names. Keep them short as your browser can only send a limited number of characters to the database at any one time.)

Advanced features using CSVwrite Xtra

Change the send button for an image
With CSVwrite Xtra you can change the send button for an image.
Change line: <input type="submit" value="[CSVwrite Xtra]">
For this: <input type="image" src="send.gif">

Alternative database & thank you page feature
If you are using the advanced features to use different database and thank you pages with the same script you will need to add the code into your form.

To use the database you put for 'db1' by using a hidden field in a form:
<input type="hidden" name="mydatabase" value="db1">

To use the thank you page you put for 'tq1' by using a hidden field in a form:
<input type="hidden" name="mythankyou" value="tq1">

As part of a drop-down menu your code would look like this:


Using the file upload feature
If you are using the file upload feature you must check with your host first, most hosting providers will block this feature. The script will put the file in your chosen directory and add the file name to the database field.

You will need to change your input form, forms with upload must start with
<FORM action=csvwrite.pl method=post ENCTYPE="multipart/form-data">

To add a field for the upload and add the browse button just add the code below
<input type="file" name="fieldname">

An example of such form can be downloaded here !

Specify your required fields from the form

This will only work if you did set $required_fields_form to 1.

Set the field names in your form that require data. The script can check for any data, just numbers or just an email address:
<input type="hidden" name="required_fields" value="field,field2">
<input type="hidden" name="required_fields_numbers" value="field,field2">
<input type="hidden" name="required_fields_email" value="field,field2">

Back to top


Create the 'Thank You' page

The 'Thank You' page has no special requirements. You can use any page on your website.  If you set $display_data_on_thankyou to 1, you can use tags like [[fieldname]] in your page which the script will replace by the value of field fieldname.

If you have also $use_includes set to 1, you will be able to use tags like [[include1]], [[include2]], ...  to include HTML files into your Thank You page.  This is however not needed when $display_data_on_thankyou is set to 0 as you can use normal SSI includes then.

 
 

home | rate the scripts | community support forum | © www.ezscripting.com