Click here to get back home

using cgi.pm

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
using cgi.pm Ela 03-27-2008
---> Re: using cgi.pm Joost Diepenmaa...03-27-2008
Get Chitika Premium
Posted by J. Gleixner on March 28, 2008, 11:36 am
Please log in for more thread options
Ela wrote:
>> 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;
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
}

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

Posted by John Bokma on March 28, 2008, 2:44 pm
Please log in for more thread options


> $query = new CGI;

IMO: You might want to name that scalar $cgi

> print $query->header;

So this ^^ looks less silly (again, IMO).

--
John

http://johnbokma.com/perl/

Posted by xhoster on March 27, 2008, 12:11 pm
Please log in for more thread options
> 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.


Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap