Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Form Action

by Zcity (Novice)
on Jun 30, 2006 at 18:51 UTC ( #558651=perlquestion: print w/ replies, xml ) Need Help??
Zcity has asked for the wisdom of the Perl Monks concerning the following question:

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"; }

Edit: g0n - code tags

Comment on Form Action
Download Code
Re: Form Action
by jdtoronto (Prior) on Jun 30, 2006 at 19:18 UTC
    I suppose it would be easier if we knew what it was supposed to do. You are generating the form and then depending on the name of the submit button you set a variable, but what is it supposed to do after that? Is the form submitting back to this same CGI somehow?

    jdtoronto

Re: Form Action
by ahmad (Hermit) on Jun 30, 2006 at 19:26 UTC

    you're not dealing with $action variable in the right way ... plus i think you might not need it

    if you want to to preform what comes inside "createreply.cgi" file you should change this line

    $action = "createreply.cgi";

    into this require "createreply.cgi";

    HTH

Re: Form Action
by Joost (Canon) on Jun 30, 2006 at 23:28 UTC

      Thanks to All for the help. Anyways, i got it to work by doing this:

      print "Content-type: text/html\n\n"; print "<HTML>\n"; print "<HEAD>\n"; print "<TITLE>Forum</TITLE>\n"; print "</HEAD>\n"; print "<BODY>\n"; print "<FORM METHOD=POST>\n"; print "<INPUT TYPE='submit' VALUE='Preview' name='preview' onClick=thi +s.form.action='preview.cgi';this.form.target=''>\n"; print "<INPUT TYPE='submit' VALUE='Submit Reply' name='reply' onClick= +this.form.action='createreply.cgi';this.form.target=''><br>\n"; print "</FORM>\n"; print "</BODY>\n"; print "</HTML>\n";

      Code tags added by GrandFather

        using here-docs will make that output code cleaner and resolve some quoting issues (your onClick values will be problematic as-is)...
        print <<EOF; Content-type: text/html <HTML> <HEAD> <TITLE>Forum</TITLE> </HEAD> <BODY> <FORM METHOD="POST"> <INPUT TYPE="submit" VALUE="Preview" name="preview" onClick="this.fo +rm.action='preview.cgi';this.form.target=''"> <INPUT TYPE="submit" VALUE="Submit Reply" name="reply" onClick="this +.form.action='createreply.cgi';this.form.target=''"> </FORM> </BODY> </HTML>
        or, using CGI:
        print header, start_html( -title => 'forum' ), start_form( -method => 'POST' ), submit( -name => 'preview', -value=>'Preview', -onClick => "this.for +m.action='preview.cgi';this.form.target=''" ), submit( -name => 'reply', -value=>'Submit Reply', -onClick => "this. +form.action='createreply.cgi';this.form.target=''" ), end_form, end_html, ;
Re: Form Action
by virtuemart1 (Initiate) on Oct 20, 2011 at 02:29 UTC
    I got similar question about html form, action attribute.

    Firstly, the perl script file have to be inside /cgi-bin directory?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (19)
As of 2014-07-31 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (252 votes), past polls