CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Submit PHP form to perl script

 



bhumika
Novice

Apr 4, 2011, 8:49 PM

Post #1 of 15 (4660 views)
Submit PHP form to perl script Can't Post

Hi,

I am new to PERL and I am trying to pass a textarea value from a PHP form to a PERL script but I am unable to do so. Can anybody please help me with this?


Zhris
Enthusiast

Apr 5, 2011, 1:36 PM

Post #2 of 15 (4628 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

Hi,

Example PHP form:

Code
<?php 
?>
<form method="post" action="script.pl">
<textarea name="mytextarea">textarea content</textarea>
<input type="submit" name="submit" value="submit" />
</form>


Example Perl script (script.pl), to retrieve form data:

Code
#!/usr/bin/perl 
use strict;
use warnings;
use CGI ':standard';

my $mytextarea = param('mytextarea');

print "Content-type: text/html\n\n";
print "$mytextarea";


Look into the CGI module for more information (http://search.cpan.org/dist/CGI/lib/CGI.pm).

Chris


(This post was edited by Zhris on Apr 5, 2011, 2:17 PM)


bhumika
Novice

Apr 5, 2011, 6:24 PM

Post #3 of 15 (4612 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

Thank you but I get this error
"Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
Premature end of script headers: *.pl"

I am using XAMPP on Vista


Zhris
Enthusiast

Apr 5, 2011, 11:42 PM

Post #4 of 15 (4601 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

I'm sorry, I have no experience in using XAMPP. There could be any number of reasons for the error you receive. Just search it in google.

Have you ever managed to get any Perl script to run, even a simple "Hello World!" one?

Chris


bhumika
Novice

Apr 6, 2011, 12:01 AM

Post #5 of 15 (4598 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

Yes I have run "Hello World" and it is working fine and I googled for it too.

BTW thanks


Zhris
Enthusiast

Apr 6, 2011, 12:03 AM

Post #6 of 15 (4596 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

Could you post the Hello World script, so I can check for differences between the two? Unless you've got it working now.

Chris


(This post was edited by Zhris on Apr 6, 2011, 12:04 AM)


bhumika
Novice

Apr 6, 2011, 12:14 AM

Post #7 of 15 (4591 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

Yes its
#!H:/xampp/perl/bin/perl
print "content-type: text/html \n\n";

print "Hello, Perl!";


Zhris
Enthusiast

Apr 6, 2011, 12:21 AM

Post #8 of 15 (4589 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

Ok firstly, you may have already made this change, but the shebang lines are different.


Code
#!H:/xampp/perl/bin/perl  
use strict;
use warnings;
use CGI ':standard';

my $mytextarea = param('mytextarea');

print "Content-type: text/html\n\n";
print "$mytextarea";


Also is your form action correct e.g. action="http://localhost/cgi-bin/script.pl".

Test if that works.

Chris


(This post was edited by Zhris on Apr 6, 2011, 12:22 AM)


bhumika
Novice

Apr 6, 2011, 12:37 AM

Post #9 of 15 (4583 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

Yes I did that and form action is also right but gives me the same error.


Zhris
Enthusiast

Apr 6, 2011, 1:02 AM

Post #10 of 15 (4580 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

I'm sorry, i'm not really sure what else to suggest, other than to provide thing after thing to try.

Since the only difference between the working and non working scripts is the use of Perl modules, can you be certain they are installed properly.

My last suggestion is to test whether your Hello World script will work with strict alone enabled. If it doesn't work then it could be a module(s) problem:


Code
#!H:/xampp/perl/bin/perl 
use strict;

my $string = "Hello, Perl!";

print "content-type: text/html \n\n";
print "$string";


A dirty CGI method of handling forms is outlined in this tutorial - http://webdesign.about.com/od/cgi/ss/aa022299.htm, which parses the raw data from the input stream, without use of the CGI module.

Chris


(This post was edited by Zhris on Apr 6, 2011, 1:08 AM)


bhumika
Novice

Apr 6, 2011, 1:11 AM

Post #11 of 15 (4574 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

No it didnt work

I am sorry but I am new to PERL


Zhris
Enthusiast

Apr 6, 2011, 1:22 AM

Post #12 of 15 (4572 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

In H:/xampp/perl/ is there a "lib" directory. If so is "strict.pm" within.

Chris


bhumika
Novice

Apr 6, 2011, 1:25 AM

Post #13 of 15 (4570 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

no there isn't


Zhris
Enthusiast

Apr 6, 2011, 1:32 AM

Post #14 of 15 (4568 views)
Re: [bhumika] Submit PHP form to perl script [In reply to] Can't Post

Then it looks as if the Perl library didn't install properly, although I don't have any knowledge of XAMPP specifically. Maybe try re-installing XAMPP, or search for related issues.

Here is the dirty example, which should work, but its like re-inventing the wheel:


Code
#!H:/xampp/perl/bin/perl 

sub xcgi_InitForm
{
my($h) = '[a-fA-F0-9]';
my($buff, @params, $param);
my($param_name, $param_value);
local(*xcgi_form) = @_ if @_;

read(STDIN, $buff, $ENV{'CONTENT_LENGTH'});

@params = split(/&/, $buff);

foreach $param (@params)
{
($param_name, $param_value) = split(/=/, $param);

$param_value =~ tr/+/ /;
$param_value =~ s/%($h$h)/pack("C",hex($1))/eg;

$xcgi_form{$param_name} = $param_value;
}
}

{
my(@form);

xcgi_InitForm(*form);

$mytextarea = $form{'mytextarea'};

print "content-type: text/html\n\n";
print "$mytextarea";
}


Chris


bhumika
Novice

Apr 6, 2011, 2:43 AM

Post #15 of 15 (4564 views)
Re: [Zhris] Submit PHP form to perl script [In reply to] Can't Post

Thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives