Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Display the data passed from php

by sandy1028 (Sexton)
on Aug 20, 2007 at 08:37 UTC ( [id://633738]=perlquestion: print w/replies, xml ) Need Help??

sandy1028 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

How to pass the form data to perl file. I am using linux platform and i have created the .pl file in same directory where i have the php file.... /var/....../directory/contact.php

<form method="get" action="mail_contact.pl" onsubmit="return validate( +)">
I am not able to get the values in mail_contact.pl

How to pass the data

use CGI; my $q= new CGI; my $name= $q->param('name'); print $name;
The contents of whole page is displayed in the browser.
Please help me with this

Replies are listed 'Best First'.
Re: Display the data passed from php
by moritz (Cardinal) on Aug 20, 2007 at 08:58 UTC
    What do you mean by The contents of whole page is displayed in the browser?

    Are the contents of the perl script displayed in the browser, insted of its output? If that's the case, you have a problem with the configuration of your webserver, not with perl.

    And a general hint: to ease debugging of CGI scripts, start them with

    #!/usr/bin/perl use warnings; use strict; use CGI::Carp qw(fatalsToBrowser);

    And print the header as soon as you can.

      Yes the contents are displayed instead of output. Should I specify the path of cgi-bin where it is installed. Cgi-bin directory is in /var/www/cgi-bin which is the path of the server.
        With Apache you can configure any directory to serve perl CGI scripts, but you have to do that manually. (And you have to add the executable flag for the script).

        The apache doc is quite good, and there are many tutorials on the web.

        A reply falls below the community's threshold of quality. You may see it by logging in.

        The simplest way is to move the file to /var/www/cgi-bin and make it executable by doing

        $chmod +x mail_contact.pl

Re: Display the data passed from php
by Gangabass (Vicar) on Aug 20, 2007 at 08:50 UTC

    Usually CGI scripts are placed in cgi-bin directory (with 755 access rights).

    So your form must look like

    <form method="get" action="/cgi-bin/mail_contact.pl" onsubmit="return +validate()">

    Also don't forget to add

    #!/usr/bin/perl -w
    in the first line of your script (to tell server where the perl is)

      When I added the /cgi-bin/mail_contact.pl in form Got the output as
      The requested URL /cgi-bin/mail_contact.pl was not found on this serve +r. ---------------------------------------------------------------------- +---------- Apache/2.0.52 (Red Hat) Server at xxx.xxx.xx.x Port 80
        Do you have mail_contact.pl in your /cgi-bin directory?
Re: Display the data passed from php
by ww (Archbishop) on Aug 20, 2007 at 12:58 UTC
    Further questions -- for consideration once you've sorted out your permissions issues:

    1) Is the "onsubmit="return validate()" calling javascript properly -- ie, is the "return validate()" in the same page with the form? Is the validation returning what you expected? (My js fu is very weak, but the space in that function name makes me itch).
    update Same question if you're calling a php function, if that's the case, as belated reconsideration suggests?

    2) When you see the script returned in your browser, does the address bar include the name-value pairs you think you're submitting?

    3) (Style, perhaps) Is there are reason you're using "get rather than "post" in the form?

Re: Display the data passed from php
by rvosa (Curate) on Aug 21, 2007 at 18:21 UTC
    If the script's contents are returned (i.e. a bunch of perl code), your webserver is treating the script as a text file, not as something to execute. You have to do two things: i) tell your webserver the script is to be executed ii) make the script executable.

    Step i) is achieved by doing something like placing the script in a default cgi-bin folder, or changing your server's configuration so that it understands the file extension of things that are to be used as cgi executables (though outside the cgi-bin), such as *.pl or *.cgi. Step ii) is achieved by doing something like chmod +x mail_contact.pl.

    We can't really be more specific because we don't know (or particularly care about, since this is not an apache/php/js forum) your exact server configuration.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://633738]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-03-28 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found