Read POST form data

  • 11 years ago

    Hi,

    How do I read data from POST form fields that have been passed to my web page?

    Thanks,

    LazerBeam

  • 11 years ago

    The easiest way is to use CGI.pm. This will parse the POST data and provide a hash containing the data, named by the parameter:

    use CGI.pm

    my $cgiq = new CGI;
    print $cgiq->param('test');


    Would work whether "test" was passed by a POST or a GET. There is another member that you can use to determine whether this is a POST request should you need to differentiate.

  • 11 years ago

    Hi,

    Thanks for the quick reply, but I get an error.

    My code is:

    <perl>
    use CGI.pm
    my $cgiq = new CGI;
    if ($cgiq->param('stnop')==null) {
    ...
    }
    </perl>





    And my form is:

    <form action="(the URL that contains above code)" method="POST" enctype="application/x-www-form-urlencoded">
    Please type your Beta Key into the space below:<BR>
    <input type=text name="bkey=" maxlength=29 size=45><BR>
    </font>
    <font face=arial size=2>
    You can find this key in your beta invitation email. It is in the format xxxxx-xxxxx-xxxxx-xxxxx-xxxxx.
    <input type=hidden name="stnop" value="1"><BR><BR>
    <p align=right>
    <input type=submit value="      < Back      " name="bkbtn" disabled>
    <input type=submit value="      Cancel      " name="canc" disabled>
    <input type=submit value="      Next >      " name="go">
    </p>
    </form>











    And I receive this error:

    [ Error: Perl error in :
    syntax error at (eval 1993) line 2, near "use CGI." ]

    I am very new to Perl, can anyone explain this one?

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare