Solved

form processing

Posted on 1998-02-03
1
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

733 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