LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-04-2008, 07:04 PM   #1
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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)?
 
Old 02-04-2008, 08:56 PM   #2
shakezilla
Member
 
Registered: Jun 2005
Location: U.S.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78

Rep: Reputation: 16
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?
 
Old 02-04-2008, 10:25 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Original Poster
Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 02-04-2008, 11:22 PM   #4
shakezilla
Member
 
Registered: Jun 2005
Location: U.S.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78

Rep: Reputation: 16
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>
	<input type="hidden" name="itemId">A-001_weGotThisFromA</input>
	<input type="text" name="itemQty"></input>
</form>
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
 
Old 02-04-2008, 11:33 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Original Poster
Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 02-05-2008, 12:00 AM   #6
shakezilla
Member
 
Registered: Jun 2005
Location: U.S.
Distribution: xubuntu 8.10, linux 2.6.27-11-generic
Posts: 78

Rep: Reputation: 16
Ok, I've misunderstood your problem. I'm out of my league on this one, so hopefully someone else here can lend a hand.
 
Old 02-05-2008, 12:12 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Original Poster
Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
"I'm out of my league on this one" you and me both
Thanks for trying anyway
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating forms from basic shapes with moving parts in Java3D gvp87 Programming 0 10-30-2007 10:37 PM
HTML multiple submits rblampain Programming 1 04-09-2007 09:36 AM
Posting to CGI Forms goldcougar Linux - Newbie 1 07-02-2004 10:13 AM
Autoresponders & CGI Forms & E-mail Headers Big Brad Linux - Newbie 0 05-25-2004 06:45 AM
cgi-bins and fill out forms sachitha Programming 4 03-22-2004 02:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration