Any Help? Stuck trying to create cgi perl program

Discussion in 'Perl Misc' started by shadkeene@hotmail.com, Apr 18, 2007.

  1. Guest

    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.
     
    , Apr 18, 2007
    #1
    1. Advertising

  2. Joe Smith Guest

    wrote:
    > 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
     
    Joe Smith, Apr 18, 2007
    #2
    1. Advertising

  3. Guest

    Re: Any Help? Stuck trying to create cgi perl program

    On Apr 18, 2:09 pm, Joe Smith <> wrote:
    > wrote:
    > > 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


    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
     
    , Apr 18, 2007
    #3
  4. Ala Qumsieh Guest

    Re: Any Help? Stuck trying to create cgi perl program

    Michele Dondi wrote:

    > On 18 Apr 2007 14:53:32 -0700, wrote:
    >
    >>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,

    >
    > 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
     
    Ala Qumsieh, Apr 19, 2007
    #4
  5. Guest

    Re: Any Help? Stuck trying to create cgi perl program

    On Apr 18, 2:09 pm, Joe Smith <> wrote:
    > wrote:
    > > 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


    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
     
    , Apr 19, 2007
    #5
  6. Guest

    Re: Any Help? Stuck trying to create cgi perl program

    On Apr 19, 8:48 am, wrote:
    > On Apr 18, 2:09 pm, Joe Smith <> wrote:
    >
    >
    >
    >
    >
    > > wrote:
    > > > 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

    >
    > 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
     
    , Apr 19, 2007
    #6
  7. Re: Any Help? Stuck trying to create cgi perl program

    wrote:
    > 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
     
    Jürgen Exner, Apr 19, 2007
    #7
  8. Guest

    shorter question ref. simple code

    On Apr 19, 8:52 am, wrote:
    > On Apr 19, 8:48 am, wrote:
    >
    >
    >
    >
    >
    > > On Apr 18, 2:09 pm, Joe Smith <> wrote:

    >
    > > > wrote:
    > > > > 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

    >
    > > 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- Hide quoted text -
    >
    > - Show quoted text -


    > > On Apr 18, 2:09 pm, Joe Smith <> wrote:

    >
    > > > wrote:
    > > > > 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

    >
    > > 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- 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
     
    , Apr 19, 2007
    #8
  9. Guest

    Re: Any Help? Stuck trying to create cgi perl program

    On Apr 19, 9:04 am, "Jürgen Exner" <> wrote:
    > wrote:
    > > 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


    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
     
    , Apr 19, 2007
    #9
  10. Re: Any Help? Stuck trying to create cgi perl program

    <> wrote:
    > On Apr 19, 8:48 am, wrote:


    >> 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...



    "an" is singular, you have plural errors. :-(


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 20, 2007
    #10
  11. Joe Smith Guest

    Re: Any Help? Stuck trying to create cgi perl program

    wrote:

    > 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
     
    Joe Smith, Apr 20, 2007
    #11
  12. Guest

    Re: Any Help? Stuck trying to create cgi perl program

    Thanks for your help...I have it working now...
    Shad
     
    , Apr 26, 2007
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D. Shane Fowlkes
    Replies:
    3
    Views:
    378
    MasterGaurav
    Feb 23, 2005
  2. HC
    Replies:
    2
    Views:
    1,123
    Roedy Green
    Jul 26, 2009
  3. cayenne
    Replies:
    3
    Views:
    275
    Brian McCauley
    May 26, 2004
  4. erik
    Replies:
    19
    Views:
    529
    Gunnar Hjalmarsson
    Jun 27, 2005
  5. kath
    Replies:
    4
    Views:
    807
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page