Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Manually add parameters in perl cgi

by TheChosenOne (Initiate)
on Sep 05, 2014 at 17:44 UTC ( [id://1099715]=perlquestion: print w/replies, xml ) Need Help??

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

Hi
I've written a cgi script and it does the following:
#!/usr/bin/perl use strict; use warnings; use CGI qw(:cgi-lib :standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $q = new CGI; print $q->header; print "<center>"; print $q->h1('Let\'s do something!'); print "</center>"; print $q->start_html(-title => 'Do something'); print $q->end_form; our %in; &ReadParse(%in); my @keys = keys %in; my @values = values %in; main(); sub main{ print "<center>"; my $q0 = new CGI; print $q0->start_form( -name => 'sniff_button', -method => 'POST', -enctype => &CGI::URL_ENCODED, ); print $q0->submit( -name => 'button', -value => 'Do something', ); print $q0->end_form; print "</center>"; }
What I want to do is add some parameters manually, because the next that depends on the previous state and not only on the current state (So I have to pass a parameter twice.).
I've done stuff with param() and URI, but none of them work. Any advice?

Replies are listed 'Best First'.
Re: Manually add parameters in perl cgi
by AppleFritter (Vicar) on Sep 05, 2014 at 18:26 UTC

    Howdy, TheChosenOne, and welcome to the Monastery!

    It's not clear to me what you're trying to accomplish. Can you explain what you're trying to accomplish? Please see I know what I mean. Why don't you? and How (Not) To Ask A Question; the monks will be able to help you much more effectively once they understand your problem.

    In the meantime, here's a few general tips:

    • Start the document body before outputting <center> tags and headers.
    • Don't end a form before having started one.
    • Don't use a main() routine.
    • If you do, at least put all your "main" code into it.
    • Don't use several CGI objects for the same page.
    • In fact, if you can avoid it, don't use CGI at all, opt for one of the modern web frameworks instead.
Re: Manually add parameters in perl cgi
by zentara (Archbishop) on Sep 05, 2014 at 19:45 UTC
    Just add them like this:
    #!/usr/bin/perl use warnings; use CGI 'cgi'; use LWP::UserAgent; our ($secure_server_address,$cgi_directory); print "Content-type: text/html\n\n"; #my $test= 'FALSE'; my $test= 'TRUE'; my $relay; my $cgi = new CGI; my %input= $cgi->Vars(); foreach $name (keys %input){ $value = $input{$name}; $relay .= "$name=$value&"; } # adding fields here $relay .= "Ecom_transaction_complete=$test&"; $relay .= "IOC_response_code=0&"; open (RT,">test/respgen.test"); print RT $relay; close RT; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new (POST => "$secure_server_address$cgi_dire +ctory/boacc.pl"); $req->content_type('application/x-www-form-urlencoded'); $req->content("$relay"); my $res = $ua->request($req); print $res->as_string;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Manually add parameters in perl cgi ( no ReadParse no CGI->Vars
by Anonymous Monk on Sep 05, 2014 at 20:07 UTC

    I've done stuff with param() and URI, but none of them work. Any advice?

    Can you show that "stuff"?

    Also, "new CGI" does not mix with ReadParse , and ReadParse is just another word for CGI->new->Vars, and CGI->new->Vars is broken by design

    use CGI->param instead of CGI->Vars , CGI->Vars has caveats , its broken by design

    $ perl -MCGI -e " CGI::ReadParse(); dd( \%in )" ro=row ro=you bo=boat +bo=diddly { # tied CGI bo => "boat\0diddly", ro => "row\0you", }
    You know what \0 is? Its null character ...
    use Data::Dump qw/ dd /; use CGI; my $q = CGI->new('ro=row;ro=you;bo=boat;bo=diddly'); my %in = map { $_ => [ $q->param($_) ] } $q->param ; dd( \%in ); __END__ { bo => ["boat", "diddly"], ro => ["row", "you"] }

    Also there should be no code outside of subs, pass arguments and write more subs like sub DebugCGI in UTF-8

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-17 05:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found