in reply to Re: Getting Variable value after submitting cgi form
in thread Getting Variable value after submitting cgi form

Hi, As advised i used the hidden field, still am not able to access the server/host name. Please check the following code snippet.
========================== ## FILE: test.cgi ## use CGI::Pretty qw( :html3 :standard ); my $cgi = new CGI; print $cgi->header, $cgi->start_html('Submit User id'); print $head; print start_form(); my $host = $cgi->param('host'); print "<font color=green> Please Enter the UserID for $host: </font>"; print $cgi->text_field('USER','',10); print "\t\t".submit('action','Submit'); $cgi->hidden( -name=>'server', -value => $cgi->param('host')); if (param()) { my $test= $cgi->param('action'); if( $cgi->param('action') eq 'Submit') { my $server = $cgi->param('server'); my $user_id = $cgi->param('USER'); print "UserID: $user_id and HOST: $server " ; } } print endform; ## END of HTML form print end_html;

Replies are listed 'Best First'.
Re^3: Getting Variable value after submitting cgi form
by Corion (Patriarch) on Jun 09, 2009 at 11:59 UTC

    From your top node:

    ... test.cgi?host=$linux_host ...

    In your script:

    ... my $server = $cgi->param('server'); ... print "UserID: $user_id and HOST: $server " ;

    You will need to make sure you use consistent names everywhere.

      Hi Corion, I have used my $server = $cgi->param('server'); to get the hidden variable and before this i have used my $host = $cgi->param('host'); to get the host name from the master.cgi. Please let me know if i am doing any thing wrong in accessing hidden variable. Rehards SS
      my $host = $cgi->param('host'); print "<font color=green> Please Enter the UserID for $host: </font>"; print $cgi->text_field('USER','',10); print "\t\t".submit('action','Submit'); $cgi->hidden( -name=>'server', -value => $cgi->param('host')); if (param()) { my $test= $cgi->param('action'); if( $cgi->param('action') eq 'Submit') { my $server = $cgi->param('server');

        Your code does not even compile. There is no ->text_field method in CGI, and you're mixing object- and non-object calls to CGI.

        Take a look at the generated HTML and you will find that $cgi->hidden(...) does not output the HTML. You will need to print it out like in the rest of your code.

        use strict; use CGI; my $cgi = CGI->new; my $host = $cgi->param('host'); print "<font color=green> Please Enter the UserID for $host: </font>"; print $cgi->textfield('USER','',10); print "\t\t".$cgi->submit('action','Submit'); print $cgi->hidden( -name=>'server', -value => $cgi->param('host')); if ($cgi->param()) { my $test= $cgi->param('action'); if( $cgi->param('action') eq 'Submit') { my $server = $cgi->param('server'); print "Server is $server\n"; }; }; __END__ >perl -w tmp.pl host=foo Use of uninitialized value in string eq at tmp.pl line 13. <font color=green> Please Enter the UserID for foo: </font><input type +="text" na me="USER" size="10" /> <input type="submit" name="action" val +ue="Submit " /><input type="hidden" name="server" value="foo" />