0

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?

5
  • What do you mean by parameters? Explain exactly what you're trying to do and not how you're trying to do it. Commented Sep 5, 2014 at 17:48
  • 5
    Do you mean "I want to cause a parameter to be submitted along with those provided by the user"? Use a hidden field. Commented Sep 5, 2014 at 17:53
  • Thanks bro. A hidden field did the job (y). Commented Sep 6, 2014 at 12:55
  • Where are you learning CGI programming from? this looks like a CGI program from 15 or 20 years ago. Please try to pick up few less outdated habits. Commented Sep 8, 2014 at 9:24
  • From the perldoc: perldoc.perl.org/CGI.html Commented Sep 8, 2014 at 12:24

1 Answer 1

1

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>";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.