Basic CGI: 2 forms, 2 submits: HOW?
This is a basic CGI qn I'm sure, but I don't know how to make it work.
I've got 2 forms, A & B, both of which work fine standalone (and both have a submit button). What I need to do is call B from A, passing a couple of params. If I do this by adding B's code to the file containing A's code, or putting B in a perl module (my pref as there will be about 25 different form Bs to call) & clicking A's submit, then form B comes up fine and (in update mode) fills the fields from the DB. However, ctrl seems to pass back to the calling form A in the background, such that when I click the submit button on form B (which is displayed), it actions the form A submit button, so the form B is not actioned(!). I also tried using system() or exec() instead, but they just fail with 'unexpected end of headers' and don't even load B. FYI, I'm using CGI::FormBuilder, but I believe this is a generic CGI qn; how do you use multiple forms, each with their own submit (pref separate code files for each)? |
At the risk of a n00b questioning someone of 2000 someodd posts, why exactly are you doing this? Is it because you're POSTing to 2 different servers? If that's the case, couldn't the CGI script receive info from one form and POST to another server from within itself?
|
Actually, I'm new to CGI myself ... that's why I'm stuck ;)
No, script/form A allows you to choose an item type and either create a new one or update a known one. If a known one, also enter the item id eg itemA-001. Then call form B from A (by clicking A's submit button). There will be one script/form 'B' for each item type. Create or update item as requested. Click submit button on form B to insert/update DB. As separate / standalone scripts/forms, they work fine. Calling B from A, B appears, but the prog context seems to rtn to A after displaying B, so although I click on B's submit, I actually get A's action. I believe it's something to do with CGI being a stateless protocol, but I don't know how to deal with that. |
Well I don't think I can help you with the 2 forms issue, because I've never dealt with anything like that. All the cgi I've ever done has been from the assumption of a single cgi request having either one GET, one POST, or both, but never more than one of each.
The only advice I can give you is to work on your process flow so your app fits into the above model. Correct me if I'm wrong, but it sounds like you want to process info from A, then form B is dependent on that, then after clicking SUBMIT on B, all the relevant data (from both A and B) is sent to the server. If this is your case, then the hidden input type may be useful to you. The hidden type will allow you to capture values from A and "store" them temporarily in B. Code:
<form> Hope that helps. EDIT ---- Just thought of one more thing. With the above method, you may actually be able to use 2 <form>'s on a single page, just form A won't have an action. Then use some pretty slick JS to auto fill in the hidden inputs, resulting in 1 server request instead of 2. But warning, that JS will be complicated, don't mess with that unless it's justified by a need for high volume. |
Passing data from A to B is no problem.
The problem is that once I've called B eg (pseudo code, conceptually) Code:
(in A) |
Ok, I've misunderstood your problem. I'm out of my league on this one, so hopefully someone else here can lend a hand.
|
"I'm out of my league on this one" you and me both :)
Thanks for trying anyway |
All times are GMT -5. The time now is 04:38 AM. |