POST problems - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

POST problems

I have a form that uses the POST method to send data to a CGI script. The form looks like this:

[code]

Name:
Email:
Message:



[/code]

Problem is, nothing is received by message.cgi. I check which REQUEST_METHOD is being used and it tells me GET. When I read from STDIN, I get nothing.

Now when I modify message.cgi so it works for the GET method and type in the values in the URL, it works so it's not a server problem.

The code in message.cgi is this,

[code]
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
print "Buffer: $buffer
";
[/code]

...pretty standard stuff but there is nothing in buffer.

Any suggestions?

Thanks,

Alan

Comments

  • hey, i dunno why thats not working but anyway ive got a subroutine that'l make life alot easier for you...

    [code]
    sub read_input
    {
    local ($buffer, @pairs, $pair, $name, $value, %FORM);
    $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
    if ($ENV{'REQUEST_METHOD'} eq "POST")
    {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    } else
    {
    $buffer = $ENV{'QUERY_STRING'};
    }
    # Split information into name/value pairs
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs)
    {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%(..)/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
    }
    %FORM;
    }
    [/code]

    now all thats left to is use it:
    [code]
    my %query = &read_input;
    [/code]

    so say your form had a textbox called "email" you use:
    [code]
    $query{email}
    [/code]
    to get whatever the submitter entered, also it will automatically fix up any special characters sent into the form.

    Hope it works for you!!
Sign In or Register to comment.