CGI Development

Moderators: Jonathan
Number of threads: 55
Number of posts: 121

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
POST problems Posted by alantangcs on 31 Dec 2001 at 7:14 PM
I have a form that uses the POST method to send data to a CGI script. The form looks like this:

    <form action="cgi-bin/message.cgi" method="POST">
            Name:  <input type=text name="name">
            Email: <input type=text name="email">
            Message:
            <textarea name="message" cols=48 rows=5></textarea>
            <input type="submit" value="Post">
    </form>


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,

    read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    print "<b>Buffer:</b> $buffer\n";


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

Any suggestions?

Thanks,

Alan
Report
Re: POST problems Posted by rinmak on 7 Feb 2002 at 5:16 AM
hey, i dunno why thats not working but anyway ive got a subroutine that'l make life alot easier for you...

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;
}


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


so say your form had a textbox called "email" you use:
    $query{email}

to get whatever the submitter entered, also it will automatically fix up any special characters sent into the form.

Hope it works for you!!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.