in reply to help with cgi submit buttons

submit() doesn't return the name or the value of "the submit button". it just generates html.

you need something like

if (param('hello') eq 'Hello') { } elsif (param('hello1') eq 'Hello1') { }
UPDATE: I thought this was "pseudo code". Apparently not.

Take note that the submitted values can not be read by perl until the form is submitted (i.e. way after you've already generated the HTML and send it to the browser). In other words, $action will always be empty in your code.

You can fix this in javascript, or use a single action url for the form. or use two forms.

Replies are listed 'Best First'.
Re^2: help with cgi submit buttons
by Zcity (Novice) on Jun 29, 2006 at 19:55 UTC
    Thanks.. i modified it a bit and got it to work submit(-name=>'hello', -values=>'hello'),
    submit(-name=>'jello', -values=>'jello'),
    end_form,
    hr;
    if (param('hello') eq 'hello') {
    print "hello";
    }
    if (param('jello') eq 'jello') {
    print "hello1";
    }
      Now Im having problem making the $action variable perform the right action.. Is there something Im missing..
      ##################################### #!/usr/local/bin/perl -wT use CGI qw/:standard/; use strict; use CGI::Carp qw/fatalsToBrowser/; #use Mail::Sendmail; $CGI::POST_MAX = 10000; my $filename = param('filename'); my $action; my $method = "Post"; my $preview = "preview_form.cgi"; my $submit = "createreply.cgi"; my $issues = param('issues'); my $email = param('email'); print header; print start_html('MD Best Practices Forum'), h1('Mechanical Disciplines'), p, h2('Best Practices Executive Forum'), start_form(-method=>$method,-action=>$action), hidden(-name=>'filename', -value=>''), hidden(-name=>'to', -value=>''), hidden(-name=>'from', -value=>''), "What's your beef? ", p, textarea(-name=>'issues', -rows=>'10', -columns=>'60'), p, "Reply from: popup_menu(-name=>'email', -values=>['Select Manager','David','Mark']), submit(-name=>'recommendedby', -value=>'Recommended by'), p, submit(-name=>'submitreply',-value=>'Submit Reply'), submit(-name=>'closefile', -value=>'Close File'), submit(-name=>'preview', -value=>'Preview'), reset(-name=>'reset', -value=>'Reset'), submit(-name=>'submittodept', -value=>'Submit to Dept'), end_form, hr; if (param('preview') eq 'Preview') { print "<P>Your message: <I>$issues</I>\n"; print "<P>Manager: <I>$email</I>\n"; } if (param('submitreply') eq 'Submit Reply') { $action = "createreply.cgi"; }

      20060703 Janitored by Corion: Restored content, added code tags, as per Writeup Formatting Tips