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

Hi,

I'd like to seek more wisdom regarding posting of values.

I am in a radical project where i was tasked to build a UI with XUL generated from perl (Template::Declare) i have no problems with the UI but with the forms.

I can't use inserting html elements because it sometimes does not display therefor useless. I can't seem to use XMLhttpRequests... I tried to use CGI.pm but it returned the whole page... something must be wrong here somewhere. (i'll try this again next time) I am now trying to use LWP but as extensive as I've read, all of them are posting to a PHP script.

If ever I get to implement the html element, the XMLhttpRequest, the CGI, and the LWP it will just bring me back to the problem that somehow how can I capture/receive the values passed from my form to the perl script?

something similar to:
<?php header("Content-type: text/html"); while (list($key, $val) = each($_REQUEST)) { echo "$key = $val\n"; } ?>

to expand things more.. I that perl script will access the database (no problem with this) and return a value back to my form (will pose another problem of posting/returning a value).

Many thanks... Hoping that someone has an idea on what to do... I'm open in learning things.. just that.. it has to be perl, xul, and html ^^,

roiji-

Replies are listed 'Best First'.
Re: POSTing values to a perl script
by moritz (Cardinal) on Dec 17, 2007 at 10:01 UTC
    You can use CGI:
    use CGI qw(param header); print header(); my @keys = param(); for (@keys){ print "$_ = ", param($_), "\n"; }
Re: POSTing values to a perl script
by olus (Curate) on Dec 17, 2007 at 12:31 UTC
    And you can also get everything into an hash.
    use strict; use CGI; # get all posted parameters my %request = Vars; #print everything print "Content-type:text/html\n\n"; foreach my $key( keys %request) { print "$key = $request($key) \n"; }
Re: POSTing values to a perl script
by Gangabass (Vicar) on Dec 17, 2007 at 09:59 UTC

    You forgot to show us your attempt to use CGI.pm code.

    use CGI; .....
      Yup i forgot to and I lost it somewhere :-(

      Turns out, sending part was wrong... I got mixed up with the id and name attributes...

      I'll try the CGI today... I'll post the script when I got it running... ...or not running.. heh' Thanks all for the reply ^^,

      -roiji
Re: POSTing values to a perl script
by roiji (Initiate) on Jan 03, 2008 at 05:43 UTC
    i finally got to run the serverpost element of XUL (this uses the XMLhttpRequest)
    turns out, i got mixed up with the serverpostname attribute from the element (where i will get the values from) and used name instead of the id attribute for the serverpost element..
    here's the perl generated XUL code
    <http:serverpost id="foo" #i used 'name' before... that did not work. targetURL="/cgi-bin/logger.pl" onHTTPResponseReceived="alert('this.responseText;')" />
    and used the CGI
    #!/usr/bin/perl -w use CGI; #CGI stuff my $q = new CGI; my %f; #($f) should be declared as a hash foreach my $i ($q->param()) { $f{$i} = $q->param($i); } my $empid = $q->param('empid'); my $code = $q->param('code'); #sql things follow...
    thanks everyone for the enlightenment~