Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Perl from PHP

by koolgirl (Hermit)
on Nov 07, 2012 at 14:19 UTC ( #1002676=perlquestion: print w/ replies, xml ) Need Help??
koolgirl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I have been absent quite some time, stuck in web world (yawn). I have a Perl question and can not seem to figure it out, so I am back to annoy the monastery once again (seems to be a skill I have).

I have a WordPress website I am working on for a client, I know I know - **ducks to avoid a mouse hitting forehead**. I am integrating a form on the site, with GoTo Training, see This Page for a quick doc overview of the process involved. The API can not interact with the form directly, so I am using good old Perl.

However, since WordPress is written in php, my form which uses simply the action call to run the script (from the cgi-bin of course) does nothing. I have searched and searched and the only things I seem to be coming up with. are system and exec calls. However this doesn't seem to want to work, as my form is coming from a static page within wp.

Does anyone have a clue, how one would call a Perl script from an HTML form, buried in PHP, without actually using php itself? (if that makes any sense - as it's cumbersome to try and get php to execute from within a page) as in a system call, exec, etc., because the "plug ins" required to actually execute php from within a page, affect the entire site and are very clumsy.

Here is my form, very simple, just a name, last name and email:

<form action="/cgi-bin/process.pl" method="POST" ><div id="trial_form" +>First name: <input type="text" name="givenName" /></div><div id="tri +al_form">Last name: <input type="text" name="surname" /></div><div id +="trial_form">Your Email: <input type="email" name="email" /></div><p +><input type="submit" value="Submit" /></p></form>

Added - By the way - I have no desire to use php, I loathe the language, please understand that I am aware of the backlash I may cause by attempting to do so, but I refuse to do it in php, so with Perl from within php is my other option....that being said, please check all pitchforks and torches at the door ;-)

ADDED 11/09/12 (almost 11/10/12) - So, it seems all of you were quite right, nothing to do with php (likely culprit in my world, but nonetheless). However, I am not quite sure what the problem was...however, I did realize that, when I ran it outside the cgi-bin, just from public_html - worked fine (as in got a response). Not sure of that issue, especially since it certainly should be completely backwards, but I can not find the issue, as the cgi-bin and public_html both have identical config and permissions, but of course my access is a bit limited to the server. I eliminated the form, and ran it from my system (command line), and finally got to where I was at least getting a response. Now, my issue is getting the content in JSON, and dealing with a bad install of the JSON module, which cpan refuses to realize is gone. I am probably going to just delete Perl (strawberry) and reinstall (ActiveState). However, this OAuth token business was pretty complicated, so at least I got that leg work finished. =) Thanks, greengaroo, Limbic~Region (my old buddy - glad to see ya ;-), fullermd and spacemonk (and of course Voronich and Tanktalus <--- although the later really just goofed around with me while I avoided the work entirely =), and all the other monks in the cb and elsewhere ;-), not telling, who helped me. I keep waiting for this moment when I just sort of morph into a bad ass Perl hacker - sort of like a telephone booth clothes change for Wonder Woman (I can not recall how she changed - was it a phone booth?) but instead the bad guys keep kicking my arse. One day - one day, Monks....=)

Comment on Perl from PHP
Download Code
Re: Perl from PHP
by greengaroo (Hermit) on Nov 07, 2012 at 14:29 UTC

    This should work fine. Can you try putting the absolute URL in the "action" of the form, just for testing if this works?

    Testing never proves the absence of faults, it only shows their presence.

      I did (I used /public_html/cgi-bin/process.pl) and the full host path, both of those searched for pages that didn't exist. When using the one posted, it just goes to a blank white page (which is strange it seems the script would show up there) and the script doesn't run. I have also tried running the script as ".cgi" with no change in results either.

        You may be missing this in your Perl cgi script:

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

        In Perl you absolutely need this as your first output string to print a HTML page.

        Testing never proves the absence of faults, it only shows their presence.
Re: Perl from PHP
by Limbic~Region (Chancellor) on Nov 07, 2012 at 18:20 UTC
    koolgirl,
    Rather than assume the problem is with PHP posting to a Perl CGI, first verify that you can run a Perl CGI directly. There could be a number of problems - the script doesn't have the correct ownership, permissions, isn't printing out headers, etc. If it were one of those issues - I would expect an error message rather than a white screen. More likely, something isn't working the way you expect and you are looking in the wrong broom closet.

    Write the simplest hello world CGI you can. Verify it works directly. Replace the POST action to the hello world. Verify it works.

    Cheers - L~R

      +1 to the above

      Remember, PHP doesn't have anything to do with POST'ing to your perl script. The user's browser posts to your perl script. And really, it doesn't even do that; it POST's to a URL. The browser doesn't know anything about PHP or perl, all it knows is that it has some HTML coming in one side, that tells it to send some HTTP stuff to this other URL.

      So your problem probably is either (a) the perl script not D'ingTRT as a CGI, or (b) the URL you're putting in not going to it. Or possibly a variant of both as (c) the server not being configured to run external CGI's, either where you put it, or anywhere.

      Luckily, they all have the same solution; forget the path you're currently taking to get there (the form), and the current contents of the script (whatever processing on the data). Just replace it with a bog-simple hello-world style script, and fiddle around until you can hit it directly and get the expected output. Then just dropping in the real code and the URL in the form will probably Just Work.

Re: Perl from PHP
by space_monk (Chaplain) on Nov 07, 2012 at 19:58 UTC
    I'm not sure this opinion will get any respect around here, but I suggest you have a rethink.

    If it's feasible to stay in one language for a project then you should do so. A mix of PERL and PHP makes for a project that's less maintainable in the long run.

      But sometimes, you don't have a choice. Particularly when you try to integrate new and old systems.

      Remember: Perl is the Force that binds the galaxy together... or was it duck tape? I'm not sure...

      Testing never proves the absence of faults, it only shows their presence.
        Yes, true, but on the facts presented this isn't the problem in this case. It's performing actions like the one proposed that results in the requirement for programming Duck Tape in the first place.....
Re: Perl from PHP
by greengaroo (Hermit) on Nov 07, 2012 at 20:11 UTC

    Hey koolgirl, if you find the solution by yourself, can you please share it with us so others could benefit from it too? Thanks!

    Testing never proves the absence of faults, it only shows their presence.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002676]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-11-28 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (193 votes), past polls