using cgi.pm

J

Joost Diepenmaat

Ela said:
After studying:

http://search.cpan.org/src/LDS/CGI.pm-3.34/cgi_docs.html#checkbox_group

I still don't understand how to tell one cgi to call another cgi to handle
the information of a submited form, after a user has submited his form with
some choices selected. Could anybody shed some light?

In general, you just don't do that. If you want to put processing code
in separate files, just use those files from the same CGI program. IOW,
use modules. That's more efficient and less error prone than trying
to invoke stand-alone scripts from each other (not to mention that doing
that will probably not work out of the box for CGI scripts that read
POST data).

HTH,
Joost.
 
E

Ela

Joost Diepenmaat said:
In general, you just don't do that. If you want to put processing code
in separate files, just use those files from the same CGI program. IOW,
use modules. That's more efficient and less error prone than trying
to invoke stand-alone scripts from each other (not to mention that doing
that will probably not work out of the box for CGI scripts that read
POST data).

HTH,
Joost.

But in the sense of putting the search and fetch functions in the same cgi,
how come results can be generated after accepting users' input parameters? A
simple example based on my simplified codes will be appreciated~

#!/usr/bin/perl

use CGI qw:)standard);

$query = new CGI;

print $query->header;

print $query->startform;
print "Title: ",$query->textfield(-name=>'title', -justification=>'RIGHT');

print $query->submit(-name=>'button_name', -value=>'Get !');
print $query->endform;
print $query->end_html;

#the following print can be executed successfully but the resultant page is
just wield....
print $query->param('title');
print "<BR>";
 
S

smallpond

But in the sense of putting the search and fetch functions in the same cgi,
how come results can be generated after accepting users' input parameters? A
simple example based on my simplified codes will be appreciated~

#!/usr/bin/perl

use CGI qw:)standard);

$query = new CGI;

print $query->header;

print $query->startform;
print "Title: ",$query->textfield(-name=>'title', -justification=>'RIGHT');

print $query->submit(-name=>'button_name', -value=>'Get !');
print $query->endform;
print $query->end_html;

#the following print can be executed successfully but the resultant page is
just wield....
print $query->param('title');
print "<BR>";


The process that prints out a web page form is not the same process
that gets the result of filling it out and pressing the submit
button. They don't have to have any connection and don't have to
be on the same web server. I can create a search form on my website
and submit it to google, for example.

It is sometimes convenient to do them both from one cgi and sort
out which call is being made from the params, but if you are just
getting started try making the form with a static web page and
handling only the submit in the cgi. Work up from there.
--S
 
X

xhoster

Ela said:
After studying:

http://search.cpan.org/src/LDS/CGI.pm-3.34/cgi_docs.html#checkbox_group

I still don't understand how to tell one cgi to call another cgi to
handle the information of a submited form, after a user has submited his
form with some choices selected. Could anybody shed some light?

If you want one CGI to create the form and a second CGI to process the
submitted data based on that form, then the first CGI doesn't call the
second one. It tells the client browser to call the second one. You
arrange for this in the start_form function/method.

In first.cgi:

print $q->start_form(-action = 'second.cgi');

If you don't specify an action, then the action defaults to using same
script which is generating the form in the first place.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
X

xhoster

Ela said:
#!/usr/bin/perl

use CGI qw:)standard);

$query = new CGI;

print $query->header;

print $query->startform;
print "Title: ",$query->textfield(-name=>'title',
-justification=>'RIGHT');

print $query->submit(-name=>'button_name', -value=>'Get !');
print $query->endform;
print $query->end_html;

You shouldn't lie like that. You told it that this is the end of the html,
but then you go on to send more html. Most browsers will handle this
deception gracefully, but it is still bad practice.
#the following print can be executed successfully but the resultant page
# is just wield....
print $query->param('title');
print "<BR>";

What is weird about it? It does exactly what I thought it would do, the
misplaced end_html not withstanding. First it shows the form,
unconditionally, then it shows the results from the just-submitted form,
if any. That is what you told it to do. What did you want it to do?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
J

J. Gleixner

Ela said:
But in the sense of putting the search and fetch functions in the same cgi,
how come results can be generated after accepting users' input parameters? A
simple example based on my simplified codes will be appreciated~

#!/usr/bin/perl

use CGI qw:)standard);

$query = new CGI;
No need to do that when using :standard. You can simply call
the methods and you can use one print for multiple values.

print header(),
startform(),
'Title: ', textfield(-name=>'title', -justification=>'RIGHT'),
submit(-name=>'button_name', -value=>'Get !'),
endform();

No idea what the 'justification' attribute for an input element does.
print $query->header;

print $query->startform;
print "Title: ",$query->textfield(-name=>'title', -justification=>'RIGHT');

print $query->submit(-name=>'button_name', -value=>'Get !');
print $query->endform;

if ( my $title = $query->param('title') )
{
# possibly validate what's in $title before using it..
# use $title for something
# print the results as HTML
}
 

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,773
Messages
2,569,594
Members
45,121
Latest member
LowellMcGu
Top