Converting a Complex Script to use CGI

S

spud

Hi,
I have a script that runs as a unix shell script that takes an XML
file then parses it performing the tasks that are in the file. in the
event that I need to ask a question or gain user input the question is
held in the xml file allowing me to ask the question and store the
result of <STDIN>...
However I have now been asked to convert this to run as a web page so
that others that are not trust worthy of unix access may use it :(
I have never written a CGI script before so the first thing I tried
was to replace my code that asked questions with a auto generated form
html form... The trouble is that when I do this my script simply
rattles through and creates the form then continues on trying to
execute the commands in the rest of the file without waiting for me to
post the form back with the information in it :(
How would I go about creating a script that asks some questions then
performs commands from them?

Thanks in advance

Peter
 
J

Jürgen Exner

spud said:
However I have now been asked to convert this to run as a web page so
that others that are not trust worthy of unix access may use it :(
I have never written a CGI script before [...]
How would I go about creating a script that asks some questions then
performs commands from them?

The first step would probably be to ask in a NG that actually has something
to do with CGI and/or web pages.

jue
 
U

usenet

spud said:
How would I go about creating a script that asks some questions then
performs commands from them?

I presume you are using the CGI.pm module...

The problem seems to be that you are not separating out your runmodes
(states). Your program needs to see if any CGI paremeters have been
set. If not, print (only) the form and exit. If params are defined,
process them accordingly. For example (an EXTREMELY simplified
program):

#!/usr/bin/perl
use strict; use warnings;
use CGI qw{ :standard Dump };

print header();
if ( param() ) {
#parameters are defined - do something with them
print
"Your parameters are: ",
p( Dump() );
}
else {
#No parameters are known - show the input form
print
start_form(),
textfield({-name => 'stuff'}),
submit(),
end_form();
}
print end_html();

__END__

The first condition of the if{} block is executed only if parameters
have been passed to the program. If not, the else{} block is executed,
which prints the form (only). When the user fills out form elements
and hits the submit button the program is re-executed (with parameters
passed to the program), which invokes the processing defined in the
if{} block.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top