in reply to Re: Basic CGI: 2 forms, 2 submits
in thread Basic CGI: 2 forms, 2 submits

Actually, they are both separate scripts, and work standalone as I mentioned. Basically, in script A I input an action ie create or update, and for update I input an item id as well eg item-001. I then pass both params to script B, which gets the related info from the DB and displays it for possible alteration. It also displays another submit button.
The problem is that although script/form B is now displayed, it seems that the code has already returned to A, because when I click submit in B, it actually re-submits A, therefore B's changes are lost.
I think it's something to do with CGI being a stateless protocol, but I'm not a CGI prog, I do back end stuff, so I don't know how to tell it to submit the displayed form ie B.

Hope that's clearer

Chris

Replies are listed 'Best First'.
Re^3: Basic CGI: 2 forms, 2 submits
by olus (Curate) on Feb 05, 2008 at 02:11 UTC
    If you have two submit buttons on the same form you will need to check which one was clicked
    use CGI; my $q = CGI->new; my $bA = $q->param('button_A'); my $bB = $q->param('button_update'); if($bA eq "whatever") { # do whatever } if($bB eq "Update") { # do update stuff here }
Re^3: Basic CGI: 2 forms, 2 submits
by bradcathey (Prior) on Feb 05, 2008 at 03:21 UTC

    chrism01, how about some code snippets? I spend all day in CGI forms and you've lost me with your prose explanation. Nothing like a little code to illustrate what you are doing.

    I am curious, though: 1) how are you displaying/generating the HTML? and 2) how are you populating and then outputing B? (is that done in your Perl? or through some templating method?)

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
      It's Perl & CGI::FormBuilder (as mentioned). Basically in script A you choose whether to create a new asset or update a known one, pass this info (using submit button) to new script (perl module) containing script B, which attempts to create or update asset as requested. Use B's submit button to insert/update DB.
      As standalone scripts they work, but I can't get it to work (as above) if I call B from A, which is the actual requirement.
      There's (will be) a form B for each asset type

      Anyway, here's the (awful) code. Sorry it's a bit long/messy, but I don't know enough to quickly make it any shorter.

      http://www.perlmonks.org/?viewmode=public;node_id=666195 my scratchpad