Solved

form processing

Posted on 1998-02-03
1
174 Views
Last Modified: 2013-12-25
I want to process some forms online using CGI and send
the contents of the form to a data store e.g. text file

Is it possible to store the data in that file as they appear
in the form.
0
Comment
Question by:aswad012698
1 Comment
 

Accepted Solution

by:
joseph4 earned 30 total points
ID: 1831914
in order to filter out any input you *don't* want to record (such as "method=post") have the name of each input field you *do* want begin with "store" followed by a number to control the order in which they are written to the file. for example,
<input type="text" name="store1Name">
<input type="text" name="store2EmailAddress">
<input type="text" name="store3Handle">

the script:

#!/usr/local/bin/perl

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

&GetInput($buffer);

unless (open (STOREDDATA, '>>' . 'stored_data_file.txt')){
print "unable to open file";
exit;
}

foreach $key (sort keys(%FORM)) {
next unless($key =~ /^store/);
print STOREDDATA $FORM{$key};
}

print STOREDDATA "----------";

close(STOREDDATA);

##
sub GetInput
{
    $ParseWhat = $_[0];
    @forminput = split(/&/, $ParseWhat);
    foreach (@forminput)
    {
        tr/+/ /;
        ($name, $value) = split(/=/, $_);
        $value =~ s/%(..)/pack("C", hex($1))/eg;
        $FORM{$name}=$value;
    }
}



file will look like this:

name
email
handle
-------
name
email
handle
-------
etc.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now