Read POST form data

  • 12 years ago


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



  • 12 years ago

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


    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.

  • 12 years ago


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

    My code is:

    my $cgiq = new CGI;
    if ($cgiq->param('stnop')==null) {

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

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


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.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov