[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

form processing

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
aswad012698
Asked:
aswad012698
1 Solution
 
joseph4Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now