Any Help? Stuck trying to create cgi perl program

S

shadkeene

Hi,
I've been learning perl/html while creating a program where the user
fills out textboxes and checkboxes while the program places the values
from the text and checkboxes into a .csv file. However, I want all
columns in the .csv file to correspond to the same text/checkbox each
time the user fills out the form so it's easy to run graphs and such
through excel. The problem is, if a checkbox isn't checked, no value
is returned and the column in the .csv file is only filled in if the
user checks the box, resulting in a row of 12 columns one day and 8
columns the next depending on how many boxes are checked. I want a
blank or zero in the .csv column if the user doesn't fill out the
checkbox...that way there is the same number of columns filled out in
the .csv file each time the form is filled out and submitted...and
equally important, the same column corresponds to the same checkbox
each time the form is submitted.
Sorry if this is vague...the code is at work and I'm at home...just
wondering if the above can be done and if I'm going about this the
best way possible....goal is to create statistics from the form data
that folks submit. I'll post the short code tomorrow if necessary.
Thanks for any help.
 
J

Joe Smith

Hi,
I've been learning perl/html while creating a program where the user
fills out textboxes and checkboxes while the program places the values
from the text and checkboxes into a .csv file. However, I want all
columns in the .csv file to correspond to the same text/checkbox each
time the user fills out the form so it's easy to run graphs and such
through excel. The problem is, if a checkbox isn't checked, no value
is returned

That's trivial to fix. The CGI program should know the names of
all the allowable text/checkbox items. When it goes through the list
of returned items, it can supply a default value for anything that is
missing.

Since the browser and/or CGI parser may produce a list of returned
items in random order, you want to go through them in a specific
order before creating the CSV data.

@fields = qw(name addr1 addr2 phone zip box1 box2 box3);
push @output,$param{$_} || '""' for @fields;

-Joe
 
S

shadkeene

That's trivial to fix. The CGI program should know the names of
all the allowable text/checkbox items. When it goes through the list
of returned items, it can supply a default value for anything that is
missing.

Since the browser and/or CGI parser may produce a list of returned
items in random order, you want to go through them in a specific
order before creating the CSV data.

@fields = qw(name addr1 addr2 phone zip box1 box2 box3);
push @output,$param{$_} || '""' for @fields;

-Joe

Thanks Joe...yeah, I'm a beginner but saw this forum had more
activity, so I posted here. I'll give it a go and let you know how it
goes. Thanks again for such a quick answer,
Shad
 
A

Ala Qumsieh

Michele said:
You welcome. Just two picky side notes:

(i) this is *not* a "forum";

Why not? A forum, by definition, is a public place where people can meet and
exchange ideas. Newsgroups are forums.

--Ala
 
S

shadkeene

That's trivial to fix. The CGI program should know the names of
all the allowable text/checkbox items. When it goes through the list
of returned items, it can supply a default value for anything that is
missing.

Since the browser and/or CGI parser may produce a list of returned
items in random order, you want to go through them in a specific
order before creating the CSV data.

@fields = qw(name addr1 addr2 phone zip box1 box2 box3);
push @output,$param{$_} || '""' for @fields;

-Joe

Joe, I think I understand what you're doing and I've tried to apply it
to my program, but I'm getting error messages stating "@fields,
@output, %param, @fields, @output" require explicit package name.
I'll show you what I wrote:

@fields = qw(AE, EG, amTAF, pmTAF) ###where the textbox1, etc are
some names for the textboxes and checkboxes in my html code
push @output,$param{$_} || '"'" for @fields;

foreach my $i(@output) {
print OUT "$i,";
}


It looked like you were getting all the values into the @output array,
and then I'm just trying to print them out one by one into columns.
Thanks for any help as trivial as it may be.

The code I was using prior to this was utilizing hashes but didn't
return the values of unchecked boxes...

my %form;
foreach my $p (param()) {
$form($p) = param($);
print OUT "$form{$p},";
}


Shad
 
S

shadkeene

Joe, I think I understand what you're doing and I've tried to apply it
to my program, but I'm getting error messages stating "@fields,
@output, %param, @fields, @output" require explicit package name.
I'll show you what I wrote:

@fields = qw(AE, EG, amTAF, pmTAF) ###where the textbox1, etc are
some names for the textboxes and checkboxes in my html code
push @output,$param{$_} || '"'" for @fields;

foreach my $i(@output) {
print OUT "$i,";

}

It looked like you were getting all the values into the @output array,
and then I'm just trying to print them out one by one into columns.
Thanks for any help as trivial as it may be.

The code I was using prior to this was utilizing hashes but didn't
return the values of unchecked boxes...

my %form;
foreach my $p (param()) {
$form($p) = param($);
print OUT "$form{$p},";

}

Shad- Hide quoted text -

- Show quoted text -

The msg I just posted has an error...'"'" should read '""'...
Shad
 
J

Jürgen Exner

to my program, but I'm getting error messages stating "@fields,
@output, %param, @fields, @output" require explicit package name.

Did you declare the variables?
I'll show you what I wrote:

@fields = qw(AE, EG, amTAF, pmTAF) ###where the textbox1, etc are

Did you declare @fields somewhere before this line?

jue
 
S

shadkeene

The msg I just posted has an error...'"'" should read '""'...
Shad- Hide quoted text -

- Show quoted text -







The msg I just posted has an error...'"'" should read '""'...
Shad- Hide quoted text -

- Show quoted text -

A shorter question ref. the code...I know what was missing...I
declared the @fields with "my" and declared a my @output as well to
eliminate some of the errors...however, I'm still receiving an error
for the global symbol "%param" requiring explicit package. Wondering
why since %param isn't in the code. Thanks again for any help...
Shad
 
S

shadkeene

Did you declare the variables?



Did you declare @fields somewhere before this line?

jue

Jurgen...wie geht es dir? I don't know too much German, but enjoy the
language...recently visited the country during the world cup.
Just posted a msg after you replied...I declared @fields by writing my
@fields = qw(AE, EG, amTAF, pmTAF, etc) in the code. That error went
away but still have the %param error. Is the "my" enough to declare
the array @fields? Thanks,
Shad
 
J

Joe Smith

The code I was using prior to this was utilizing hashes but didn't
return the values of unchecked boxes...

my %form;
foreach my $p (param()) {
$form($p) = param($);
print OUT "$form{$p},";
}

That's exactly the thing I was warning you to not use.

If on Monday param() returns ("AE", "EG", "amTAF", "pmTAF")
and on Tuesday returns ("amTAF", "EG", "AE", "pmTAF"), then
the CSV created will be really screwed up because the fields
are not in the right order. You need to force them to be in order.

my @fields = qw(name addr1 addr2 phone zip box1 box2 box3);
print OUT join(',',@fields),"\n"; # Print header line
my @output;
push @output,(param($_) || '""') for @fields;
print OUT join(',',@output),"\n";


-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top