Solved

form processing

Posted on 1998-02-03
1
173 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

760 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

19 Experts available now in Live!

Get 1:1 Help Now