How can i write the values of a form through a cgi script in a txt file.

Discussion in 'Perl Misc' started by JR, Oct 15, 2003.

  1. JR

    JR Guest

    How can i write the values of a form through a cgi script in a txt file.

    My html pages is for example:

    <FORM METHOD=POST ACTION="script.cgi">
    <input type="text" name="nummer" size="20"></p>
    <p><input type="text" name="paswoord" size="20"></p>
    <p><input type="submit" value="Submit" name="Send">
    </form>

    Can anybody help me with this simple script
    I am a newbie and i would love to learn perl/cgi.


    Thanks
     
    JR, Oct 15, 2003
    #1
    1. Advertising

  2. JR

    Anand Guest

    Re: How can i write the values of a form through a cgi script ina txt file.

    In your cgi script names 'script.cgi' you can get values of parameter
    passed. You have to write values to file in this script.
    Let me know if you need some more input.

    --Anand

    JR wrote:
    > How can i write the values of a form through a cgi script in a txt file.
    >
    > My html pages is for example:
    >
    > <FORM METHOD=POST ACTION="script.cgi">
    > <input type="text" name="nummer" size="20"></p>
    > <p><input type="text" name="paswoord" size="20"></p>
    > <p><input type="submit" value="Submit" name="Send">
    > </form>
    >
    > Can anybody help me with this simple script
    > I am a newbie and i would love to learn perl/cgi.
    >
    >
    > Thanks
     
    Anand, Oct 15, 2003
    #2
    1. Advertising

  3. JR

    Tore Aursand Guest

    Re: How can i write the values of a form through a cgi script in a txt file.

    On Wed, 15 Oct 2003 10:33:23 -0700, JR wrote:
    > How can i write the values of a form through a cgi script in a txt file.


    What have you tried so far? What doesn't work?


    --
    Tore Aursand <>
     
    Tore Aursand, Oct 16, 2003
    #3
  4. JR

    JR Guest

    Tore Aursand <> wrote in message news:<>...
    > On Thu, 16 Oct 2003 12:57:41 -0700, JR wrote:
    > >>> How can i write the values of a form through a cgi script in a txt file.

    >
    > >> What have you tried so far? What doesn't work?

    >
    > > #!/usr/bin/perl

    >
    > Should be:
    >
    > #!/usr/bin/perl
    > #
    > use strict;
    > use warnings;
    >
    > > print "Content-type:text/html\n\n";
    > >
    > > read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    > > @pairs = split(/&/, $buffer);
    > > foreach $pair (@pairs) {
    > > ($name, $value) = split(/=/, $pair);
    > > $value =~ tr/+/ /;
    > > $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    > > $FORM{$name} = $value;
    > > }

    >
    > Should be:
    >
    > use CGI;
    >
    > my $cgi = CGI->new();
    > print $cgi->header(-type => 'text/html');
    >
    > > open (EEP,"passwords.txt");foreach $key (keys(%FORM)) {
    > > print EEP "$key = $FORM{$key}<br>";
    > > }

    >
    > Should be:
    >
    > my $params = $cgi->Vars();
    > open( EEP, '>passwords.txt' ) || die "$!";
    > foreach my $key ( keys %$params ) {
    > print EEP $key . ' = ' . $params{$key} . '<br';
    > }
    > close( EEP );
    >
    > But why do you want to write some HTML to STDOUT, while the form data gets
    > written to a text file?
    >
    > Summary:
    >
    > perldoc CGI
    > perldoc -f open


    I tried your code but i get the follow error

    Status: 302 Found Location:
    /bin/error?error=Your%20script%20produced%20this%20error%3A%20%3Cbr%3EUndefined%20subroutine%20CGI%3A%3AVars%20at%20CGI.pm%20line%20349.
    URI: /bin/error?error=Your%20script%20produced%20this%20error%3A%20%3Cbr%3EUndefined%20subroutine%20CGI%3A%3AVars%20at%20CGI.pm%20line%20349.
    Content-type: text/html
     
    JR, Oct 17, 2003
    #4
  5. JR

    Tore Aursand Guest

    Re: How can i write the values of a form through a cgi script in a txt file.

    On Fri, 17 Oct 2003 12:01:16 -0700, JR wrote:
    > I tried your code but i get the follow error


    Please post the complete code.


    --
    Tore Aursand <>
     
    Tore Aursand, Oct 19, 2003
    #5
  6. JR

    JR Guest

    Tore Aursand <> wrote in message news:<>...
    > On Fri, 17 Oct 2003 12:01:16 -0700, JR wrote:
    > > I tried your code but i get the follow error

    >
    > Please post the complete code.


    #!/usr/bin/perl
    #
    use strict;
    use warnings;

    use CGI;
    my $cgi = CGI->new();
    print $cgi->header(-type => 'text/html');

    my $params = $cgi->Vars();
    open( EEP, '>passwords.txt' ) || die "$!";
    foreach my $key ( keys %$params ) {
    print EEP $key . ' = ' . $params{$key} . '<br';
    }
    close( EEP );

    this is my complete code

    Thanks

    Jo
     
    JR, Oct 19, 2003
    #6
  7. JR

    Eric Bohlman Guest

    (JR) wrote in
    news::

    > foreach my $key ( keys %$params ) {


    Here you treat $params as the hash reference it is...

    > print EEP $key . ' = ' . $params{$key} . '<br';


    But here you're not dereferencing it, instead you're trying to look up the
    key in the non-existent hash %params. You want $params->{$key}, or
    $$params{$key} if you prefer (though I find the arrow-style easier to
    read).
     
    Eric Bohlman, Oct 19, 2003
    #7
  8. JR

    Tore Aursand Guest

    Re: How can i write the values of a form through a cgi script in a txt file.

    On Sun, 19 Oct 2003 11:15:09 -0700, JR wrote:
    >> Please post the complete code.


    > [...]
    > this is my complete code


    That's impossible. You told in the previous message that you got this
    error message:

    Undefined subroutine CGI::Vars at CGI.pm line 349

    When I run your code - as posted by you - I don't receive this error
    message. I get, however, an other error:

    Global symbol "%params" requires explicit package name [...]

    And that's because you're not dereferencing your hash when printing it out;

    print EEP $key . ' = ' . $params{$key} . '<br';
    ^^^^^^^^^^^^^
    You should use '$params->{$key}' instead.


    --
    Tore Aursand <>
     
    Tore Aursand, Oct 20, 2003
    #8
    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. Sameen
    Replies:
    2
    Views:
    463
    Victor Bazarov
    Aug 29, 2005
  2. Kishore
    Replies:
    1
    Views:
    100
    J├╝rgen Exner
    Aug 30, 2004
  3. PerlFAQ Server
    Replies:
    4
    Views:
    145
    brian d foy
    Jan 3, 2011
  4. PerlFAQ Server
    Replies:
    0
    Views:
    153
    PerlFAQ Server
    Mar 30, 2011
  5. Kenz09
    Replies:
    3
    Views:
    93
    Dave Angel
    Jul 8, 2013
Loading...

Share This Page