简体   繁体   中英

Manually add parameters in perl cgi

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?

A hidden field is the answer:

sub main{
    print "<center>";
    my $q0 = new CGI;
    print $q0->start_form(
        -name       => 'sniff_button',
        -method     => 'POST',
        -enctype    => &CGI::URL_ENCODED,
    );
    print $q0->hidden(
        -name       => 'machine_state',
        -default    => 'some_previous_value');
    print $q0->submit(
        -name   => 'button',
        -value  => 'Do something',
    );
    print $q0->end_form;
    print "</center>";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM