Re: Multiple Scripts?
by jptxs (Curate) on Nov 14, 2000 at 22:53 UTC
|
You say forms, so I assume you mean web forms, right? if so...
You could use redirects. see perldoc CGI. it goes something like:
use strict;
use warnings; # i've upgraded to 5.6 last night ;)
use CGI;
my $answer = new CGI;
if ( $date eq "today" ) {
print $answer->redirect(-uri=>'http://some.server/cgi/script.pl?dat
+e=today');
} else {
print $answer->redirect(-uri=>'http://some.server/cgi/script.pl?dat
+e=dateItIs');
}
just be sure not to print out the CGI header before doing that - which is my classic blunder when using redirects.
Update:as pointed out above by swiftone and below by Mark Dominus, you probably have form data from the first form you want to pass on to the next. I was trying to keep my example short and sweet so i skipped an example of plugging all that stuff in and settled for just putting one argument for each. But swiftone wisely points to URI::Escape as a great way to format and then feed in a complete adress + arguments to another script you may call on. Basically, don't forget to pass on all the data you've collected on the first screen somehow.
<myExperience>
$mostLanguages = 'Designed for engineers by engineers.';
$perl = 'Designed for people who speak by a linguist.';
</myExperience>
| [reply] [d/l] [select] |
|
|
I don't think that's going to work, because there was form
post data, and the posted data will probably not be redirected
to the new URL.
| [reply] |
Re: Multiple Scripts?
by Trimbach (Curate) on Nov 14, 2000 at 22:51 UTC
|
| [reply] |
RE: Multiple Scripts?
by jeroenes (Priest) on Nov 15, 2000 at 17:44 UTC
|
I really don't know if this is possible, but if it would....
Isn't it just possible to merge the two scripts into one?
The script could do a case switching on the date. You really
wouldn't have to change the scripts much, you just put them
into subs with the original parameters:
SWITCH: {
get_today(@params), last SWITCH if ($date eq 'today');
get_otherday($date,@params), last SWITCH if ($date nq 'today');
}
Moreover, you could consider splitting the >1,200 sites into
several blocks, let's say on alfabetical ranges. Just give an
extra parameter with a character, and only return those
sites beginning with that character. Would seriously reduce
load time.
If you want to use several forms right after each other, like
suggested in other replies, consider
php3||4. I use it, and
it certainly makes life very easy, because form-values
reappear as variables in php, which I eventually parse to
perl with system commands. Lazy coding is the
best.
Good luck,
Jeroen
I was dreaming of guitarnotes that would irritate an executive kind of guy (FZ) | [reply] [d/l] [select] |
Re: Multiple Scripts?
by swiftone (Curate) on Nov 14, 2000 at 22:51 UTC
|
I'm not sure I understand why you have multiple scripts at all. If you're taking the same kind of data, and doing the same kind of manipulation on it, why not fill out one form, which goes to one script, that does the calculations on the data sent?
Update: To try to answer your question though, calling a CGI script from another is usually fairly messy, because you have to make sure the parameters are sent correctly (don't forget it's the Webserver that interprets the ?blah=blah as QUERY_STRING, not the script). You can do a redirect via CGI.pm to do it, or make your scripts non-CGI, otherwise it's more trouble than it's worth.
Update2: jptxs provides a great example of redirects below. Be sure your form data is passed along in URL protected fashion (perhaps using URI::Escape?) | [reply] |
|
|
Hey guys, I wish i could show you the html, but the nextel servers wont let any ip's except 176.16.*.* in.. so let me try and elaborate.
Well, there are 2 seperate scrips. One computes the data for any given day, EXCEPT today, and the other script computes the data for today only.
The problem is, when the form is printed, the drop down box with the site names, is about 1000 entries long, and that prints 2 times, once for the today script, and the other for the date script.
What i can do, is paste the paramters:
For the Today Script:
http://172.16.4.25/cgi-bin/stats-cgi/today.pl?netid=0002-1&market=PHL
For the Anydate Script:
http://172.16.4.25/cgi-bin/stats-cgi/pickaday.pl?date=14Nov00&netid=0002-1&market=PHL
If i do do the radio button way, can i have it, so when the button is active, the form points to one script, and if it is unchecked, the form points to another?
basically what he wants is the one field, instead of being printed twice, for each script, its printed once, and based on what date is picked, it goes to the correct script?
Thanks In Advance
Dipul
| [reply] |
|
|
If i do do the radio button way, can i have it, so when the button is active, the form points to one script, and if it is unchecked, the form points to another?
basically what he wants is the one field, instead of being printed twice, for each script, its printed once, and based on what date is picked, it goes to the correct
script?
Not without Javascript (and don't go there).
So the solution is to either use what jptxs provided (but make sure you pass along your $ENV{QUERY_STRING} tacked on), or to make your two scripts non-CGI. Make them subroutines or Modules, and require/use them in the one CGI script that gets the form data.
| [reply] |
RE: Multiple Scripts?
by Trimbach (Curate) on Nov 15, 2000 at 03:20 UTC
|
Seems like alot of discussion over something that really (to
me) sounds pretty straightforward.
What about:
<code>
use CGI;
use LWP::Simple;
$q = new CGI;
$date = $q->param('date');
if ($date eq 'today') {
Gary Blackburn
Trained Killer | [reply] |
RE: Multiple Scripts?
by Trimbach (Curate) on Nov 15, 2000 at 03:20 UTC
|
Seems like alot of discussion over something that really (to
me) sounds pretty straightforward.
What about:
# Warning: untested!
use CGI;
use LWP::Simple;
$q = new CGI;
$date = $q -> param ('date');
$param1 = $q -> param ('param1');
$param2 = $q -> param ('param2');
# etc. The idea here is to load up whatever other
# parameters you plan on getting from your script.
if ($date eq 'today') {
$output = get ("http://www.foo.com/one_cgi?param1=$param1¶m2=$
+param2");
} else {
$output = get ("http://www.foo.com/two_cgi?param1=$param1¶m2=$
+param2");
}
print $q->header;
print $output;
You can do the same thing with a POST method if you need to
with a little more work.
One fish, two fish, red fish, blue fish.
Gary Blackburn
Trained Killer | [reply] [d/l] |