ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)?
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78
Rep:
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.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78
Rep:
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.
The above method can be used when you have steps in your process which are dependent on previous steps. When your CGI on the server is writing form B, have it include within B the info from A. Then the POST from B will send what you need.
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.
Last edited by shakezilla; 02-04-2008 at 11:30 PM.
Reason: one more idea
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)
get_field_vals();
call_B($arg1, $arg2); # by clicking A's 'submit' button
(in b)
collect_params();
get_data_from_DB();
display_data_for_update();
update_db(); # by clicking B's 'submit' button
prob is that the code rtns to A as soon as it's displayed the form, so when I click B's button (on screen), the code in A catches the click.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.