SlideShare a Scribd company logo
1 of 7
Download to read offline
CGI.pm Tutorial
This is a tutorial on CGI.pm which include scripts to let you see the effects. CGI.pm is a Perl module to
facilitate the writing of CGI scripts. Click here to see the details. This tutorial assumes you have a basic
knowledge of Perl and HTML.

Table of content
       What is CGI?
       First program
       Redirection Request
       Unpaired Tags
       Paired Tags
       Text Field in CGI Form
       Pop Up Menu in CGI Form
       Checkbox and Radio Button in CGI Form



What is CGI?
The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with
information servers, such as HTTP or Web servers. A plain HTML document that the Web server
delivers is static, which means it doesn’t change. A CGI program, on the other hand, is executed in
real-time, so that it can output dynamic information - perhaps a weather reading, or the latest results
from a database query.

[ Table of Content ]



First Program
The first program just invokes Perl and uses CGI.pm to print the title and heading of the web page.
#!/usr/local/bin/perl

use CGI qw(:standard);

print header;
print start_html(’This is the title’),
      h1(’This is the heading’);
print end_html;

       The first line specifies where the perl interpreter is.
       #!/usr/local/bin/perl
The second line includes the CGI Perl module and use standard symbols.
       use CGI qw(:standard);

       The third line prints the HTML header (text/html by default).
       print header;

       The fourth and fifth line prints the HTML title and heading.
       print start_html(’This is the title’),
             h1(’This is the heading’);

       The last line ends the HTML document by printing the </BODY> and </HTML> tags.
       print end_html;

[ Click here to see the effect. | Table of Content ]



Redirection Request
This program generates a redirection request for the remote browser.
#!/usr/local/bin/perl

use CGI qw(:standard);

print redirect(’http://home.school.net.hk/~hywong/redirect.html’);


       It will immediately go to the indicated URL, here is,
       http://home.school.net.hk/~hywong/redirect.html

       Absolute URLs should be used in redirection requests. Relative URLs will not work correctly.

[ Click here to see the effect. | Table of Content ]



Unpaired Tags
This program reveals the use of unpaired tags including <BR>, <P> and <HR>.
#!/usr/local/bin/perl

use CGI qw(:standard);

print header;
print start_html(-title=>’This is the title’,
                 -BGCOLOR=>’green’);
print (’This is the first line.’);
print br;
print (’This is the second line.’);
print p;
print    (’This is the second paragraph’);
print    hr;
print    (’The background color of this page is GREEN’)
print    end_html;


       This lines print out the title of the document and set the background color to green.
       print start_html(-title=>’This is the title’,
                        -BGCOLOR=>’green’);

       This line prints out the text "<br>".
       Print br;

       This line prints out the text "<p>".
       Print p;

       This line prints out the text "<hr>".
       Print hr;

[ Click here to see the effect. | Table of Content ]



Paired Tags
This program reveals the use of paired tags including <H1>, <B>, <UL> and the like.
#!/usr/local/bin/perl

use CGI qw(:standard);

print header;
print start_html(-title=>’Paired Tags’,
                  -BGCOLOR=>’yellow’);
print h1(’The Use of Paired Tags’);
print br;
print (’This is an ’, i(’italic’), ’word.’);
print p;
print ul(
         li(’1st item of an unordered list’),
         li(’2nd item of an unordered list’),
         li(’3rd item of an unordered list’)
         );
print hr;
print (’The background color of this page is ’, em(’YELLOW’));
print p;
print a({href=>"http://www.school.net.hk/~hywong/cgipmtut.html#Pair_tag"},
      ’GO BACK’);
print end_html;


       This line creates the text "<h1>The Use of Paired Tags</h1>".
print h1(’The Use of Paired Tags’);

       This line creates the text "This is an <i>italic</i> word.".
       print (’This is an ’, i(’italic’), ’word.’);

       This line prints out the text:
       <ul>
       <li>1st item of an unordered list
       <li>2nd item of an unordered list
       <li>3rd item of an unordered list
       </ul>
       print ul(
               li(’1st item of an unordered list’),
               li(’2nd item of an unordered list’),
               li(’3rd item of an unordered list’)
               );

       This line creates the text "The background color of this page is <em>YELLOW</em>".
       print (’The background color of this page is ’, em(’YELLOW’));

       This line creates the text
       "<a href="http://www.school.net.hk/~hywong/cgipmtut.html#Pair_tag>GO BACK</a>".
       print a({href=>"http://www.school.net.hk/~hywong/cgipmtut.html#Pair_tag"},
             ’GO BACK’);

[ Click here to see the effect. | Table of Content ]



Text Field in CGI Form
This program create a CGI form with text fields.
#!/usr/local/bin/perl

use CGI qw(:standard);

print    header;
print    start_html(’CGI Form with Text Field’);
print    h1(’CGI Form with Text Field’);
print    start_form;
print    "What is your name?";
print    textfield(-name=>’field_name’,
                   -size=>30);
print    p;
print    "What is your comment?";
print    p;
print    textarea(-name=>’large_field_name’,
                  -rows=>10,
                  -columns=>50);
print    p;
print    submit;
print end_form;
print hr;

if (param())
{
    print
       "Your name is ", param(’field_name’),
       p,
       "Your comment is: ", param(’large_field_name’),
       hr;
}

print a({href=>’http://www.school.net.hk/~hywong/cgipmtut.html#Text_field’},
      ’Go Back’);
print end_html;


       This line is used to start a CGI form by creating the <form> tag.
       print start_form;

       These lines create a text field of 30 characters. The name of this text field is "field_name".
       print textfield(-name=>’field_name’,
                       -size=>30);

       These lines create a large text field with 10 rows and 50 columns. The name of this text field is
       "large_field_name".
       print textarea(-name=>’large_field_name’,
                      -rows=>10,
                      -columns=>50);

       This line creates the submit button.
       print submit;

       This line is used to end a CGI form by creating the </form> tag.
       print end_form;

       These lines handle the information submitted.
       if (param())
            {
                print
                    "Your name is ", param(’field_name’),
                    p,
                    "Your comment is: ", param(’large_field_name’),
                    hr;
            }

[ Click here to see the effect. | Table of Content ]



Pop Up Menu in CGI Form
This program create a CGI form with pop up menu.
#!/usr/local/bin/perl

use CGI qw(:standard);

print    header;
print    start_html(’CGI Form with Pop Up Menu’);
print    h1(’CGI Form with Pop Up Menu’);
print    start_form;
print    "What is your favourite color?";
print    popup_menu(-name=>’color’,
                     -values=>[’red’,’orange’,’yellow’,
                              ’green’,’blue’,’indigo’,’violet’],
                     -default=>’blue’);
print    p;
print    submit(-name=>’submit button’);
print    ’      ’;
print    reset;
print    end_form;
print    hr;

if (param())
{
    print
       "Your favourite color is ", param(’color’),
       hr;
}

print a({href=>’http://www.school.net.hk/~hywong/cgipmtut.html#Pop_up_menu’},
      ’Go Back’);
print end_html;


       This line creates a pop up menu of seven values, while "blue" is the default value.
       print popup_menu(-name=>’color’,
                        -values=>[’red’,’orange’,’yellow’,
                                 ’green’,’blue’,’indigo’,’violet’],
                        -default=>’blue’);

       This line creates the submit button, with "submit button" as its name.
       print submit(-name=>’submit button’);

       This line creates the reset button.
       print reset;

[ Click here to see the effect. | Table of Content ]



Checkbox and Radio Button in CGI Form
This program create a CGI form with checkboxes and radio buttons.
#!/usr/local/bin/perl
use CGI qw(:standard);

print    header;
print    start_html(’CGI Form with Pop Up Menu’);
print    h1(’CGI Form with Pop Up Menu’);
print    start_form;
print    "What is your favourite color?";
print    checkbox_group(-name=>’color’,
                        -values=>[’red ’,’orange ’,’yellow ’,
                                 ’green ’,’blue ’,’indigo ’,’violet ’],
                        -default=>[’red ’,’blue ’]);
print    p;
print    radio_group(-name=>’color blind’,
                     -values=>[’Yes’,’No’],
                     -default=>’No’);
print    p;
print    submit(-name=>’submit button’);
print    ’      ’;
print    reset;
print    end_form;
print    hr;

if (param())
{
    print
       "Your favourite color: ", param(’color’),
       p,
       "Color blind? ---> ", param(’color blind’),
       hr;
}

print a({href=>’http://www.school.net.hk/~hywong/cgipmtut.html#Checkbox’},
      ’Go Back’);
print end_html;


       These lines create seven checkboxes, with "red" and "blue" as the default values.
       print checkbox_group(-name=>’color’,
                            -values=>[’red ’,’orange ’,’yellow ’,
                                     ’green ’,’blue ’,’indigo ’,’violet ’],
                            -default=>[’red ’,’blue ’]);

       These lines create two radio buttons, with "No" as the default value.
       print radio_group(-name=>’color blind’,
                         -values=>[’Yes’,’No’],
                         -default=>’No’);

[ Click here to see the effect. | Table of Content ]

This page is brought to you by Wong Ho Yiu Castor.
Created on 24th August, 1997.
Last modified on 30th August, 1997.

More Related Content

What's hot

Business Rules with Brick
Business Rules with BrickBusiness Rules with Brick
Business Rules with Brickbrian d foy
 
Road to Power Query NINJA – 1st STEP
Road to Power Query NINJA – 1st STEP Road to Power Query NINJA – 1st STEP
Road to Power Query NINJA – 1st STEP Takeshi Kagata
 
Domain Specific Languages (EclipseCon 2012)
Domain Specific Languages (EclipseCon 2012)Domain Specific Languages (EclipseCon 2012)
Domain Specific Languages (EclipseCon 2012)Sven Efftinge
 
Php in the graph (Gremlin 3)
Php in the graph (Gremlin 3)Php in the graph (Gremlin 3)
Php in the graph (Gremlin 3)Damien Seguy
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation TutorialLorna Mitchell
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6Andrew Shitov
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeYoav Farhi
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQLkalaisai
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16Ricardo Signes
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best PracticesJosé Castro
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPprabhatjon
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using CodeceptionJeroen van Dijk
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Salvatore Iaconesi
 

What's hot (18)

Business Rules with Brick
Business Rules with BrickBusiness Rules with Brick
Business Rules with Brick
 
Xhtml tags reference
Xhtml tags referenceXhtml tags reference
Xhtml tags reference
 
Road to Power Query NINJA – 1st STEP
Road to Power Query NINJA – 1st STEP Road to Power Query NINJA – 1st STEP
Road to Power Query NINJA – 1st STEP
 
Domain Specific Languages (EclipseCon 2012)
Domain Specific Languages (EclipseCon 2012)Domain Specific Languages (EclipseCon 2012)
Domain Specific Languages (EclipseCon 2012)
 
Php in the graph (Gremlin 3)
Php in the graph (Gremlin 3)Php in the graph (Gremlin 3)
Php in the graph (Gremlin 3)
 
Zend Certification Preparation Tutorial
Zend Certification Preparation TutorialZend Certification Preparation Tutorial
Zend Certification Preparation Tutorial
 
Creating a compiler in Perl 6
Creating a compiler in Perl 6Creating a compiler in Perl 6
Creating a compiler in Perl 6
 
PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
WordPress: From Antispambot to Zeroize
WordPress: From Antispambot to ZeroizeWordPress: From Antispambot to Zeroize
WordPress: From Antispambot to Zeroize
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
Introduction to Perl Best Practices
Introduction to Perl Best PracticesIntroduction to Perl Best Practices
Introduction to Perl Best Practices
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Refactoring using Codeception
Refactoring using CodeceptionRefactoring using Codeception
Refactoring using Codeception
 
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
Sperimentazioni di Tecnologie e Comunicazioni Multimediali: Lezione 5
 
Dsl
DslDsl
Dsl
 
Part 7
Part 7Part 7
Part 7
 
PHP Scripting
PHP ScriptingPHP Scripting
PHP Scripting
 

Viewers also liked (19)

flex_4_tutorials
flex_4_tutorialsflex_4_tutorials
flex_4_tutorials
 
my
mymy
my
 
cs3157-summer06-lab1
cs3157-summer06-lab1cs3157-summer06-lab1
cs3157-summer06-lab1
 
Ajaxworld07
Ajaxworld07Ajaxworld07
Ajaxworld07
 
spraa64
spraa64spraa64
spraa64
 
The_Perl_Review_0_6
The_Perl_Review_0_6The_Perl_Review_0_6
The_Perl_Review_0_6
 
DojoAjaxExperience2008
DojoAjaxExperience2008DojoAjaxExperience2008
DojoAjaxExperience2008
 
Intro
IntroIntro
Intro
 
gtk2-perl
gtk2-perlgtk2-perl
gtk2-perl
 
T11_effects_of_peripheral_stim
T11_effects_of_peripheral_stimT11_effects_of_peripheral_stim
T11_effects_of_peripheral_stim
 
Starters 1
Starters 1Starters 1
Starters 1
 
DojoAjaxExperience2008
DojoAjaxExperience2008DojoAjaxExperience2008
DojoAjaxExperience2008
 
instaling
instalinginstaling
instaling
 
tutorial
tutorialtutorial
tutorial
 
69-kauri
69-kauri69-kauri
69-kauri
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
Sitios web
Sitios webSitios web
Sitios web
 
corel-10-toc
corel-10-toccorel-10-toc
corel-10-toc
 
roswell_it_wiki
roswell_it_wikiroswell_it_wiki
roswell_it_wiki
 

Similar to cgipmtut

php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in functiontumetr1
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angularDavid Amend
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSencha
 
13 graph classes_2
13 graph classes_213 graph classes_2
13 graph classes_2rohikhan
 
Supercharged HTML & CSS
Supercharged HTML & CSSSupercharged HTML & CSS
Supercharged HTML & CSSMax Kraszewski
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
How to code radio buttons in HTML5 and CSS Styling
How to code radio buttons in HTML5 and CSS StylingHow to code radio buttons in HTML5 and CSS Styling
How to code radio buttons in HTML5 and CSS StylingAimeeKyra
 
VAIBHAV JAIN WEB TECHNOLOGY.pptx
VAIBHAV JAIN WEB TECHNOLOGY.pptxVAIBHAV JAIN WEB TECHNOLOGY.pptx
VAIBHAV JAIN WEB TECHNOLOGY.pptxVAIBHAV481101
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular componentsNir Kaufman
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Codemotion
 

Similar to cgipmtut (20)

php 2 Function creating, calling, PHP built-in function
php 2 Function creating, calling,PHP built-in functionphp 2 Function creating, calling,PHP built-in function
php 2 Function creating, calling, PHP built-in function
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angular
 
Introduction html
Introduction htmlIntroduction html
Introduction html
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
 
13 graph classes_2
13 graph classes_213 graph classes_2
13 graph classes_2
 
Supercharged HTML & CSS
Supercharged HTML & CSSSupercharged HTML & CSS
Supercharged HTML & CSS
 
HTML and CSS part 2
HTML and CSS part 2HTML and CSS part 2
HTML and CSS part 2
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 
Html cheatsheet
Html cheatsheetHtml cheatsheet
Html cheatsheet
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
How to code radio buttons in HTML5 and CSS Styling
How to code radio buttons in HTML5 and CSS StylingHow to code radio buttons in HTML5 and CSS Styling
How to code radio buttons in HTML5 and CSS Styling
 
Introhtml 2
Introhtml 2Introhtml 2
Introhtml 2
 
Python Menu
Python MenuPython Menu
Python Menu
 
VAIBHAV JAIN WEB TECHNOLOGY.pptx
VAIBHAV JAIN WEB TECHNOLOGY.pptxVAIBHAV JAIN WEB TECHNOLOGY.pptx
VAIBHAV JAIN WEB TECHNOLOGY.pptx
 
Styling recipes for Angular components
Styling recipes for Angular componentsStyling recipes for Angular components
Styling recipes for Angular components
 
Pp checker
Pp checkerPp checker
Pp checker
 
Php
PhpPhp
Php
 
16-DOMTree.pptx
16-DOMTree.pptx16-DOMTree.pptx
16-DOMTree.pptx
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
 
Javascript 1
Javascript 1Javascript 1
Javascript 1
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 

Recently uploaded (20)

Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 

cgipmtut

  • 1. CGI.pm Tutorial This is a tutorial on CGI.pm which include scripts to let you see the effects. CGI.pm is a Perl module to facilitate the writing of CGI scripts. Click here to see the details. This tutorial assumes you have a basic knowledge of Perl and HTML. Table of content What is CGI? First program Redirection Request Unpaired Tags Paired Tags Text Field in CGI Form Pop Up Menu in CGI Form Checkbox and Radio Button in CGI Form What is CGI? The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers, such as HTTP or Web servers. A plain HTML document that the Web server delivers is static, which means it doesn’t change. A CGI program, on the other hand, is executed in real-time, so that it can output dynamic information - perhaps a weather reading, or the latest results from a database query. [ Table of Content ] First Program The first program just invokes Perl and uses CGI.pm to print the title and heading of the web page. #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html(’This is the title’), h1(’This is the heading’); print end_html; The first line specifies where the perl interpreter is. #!/usr/local/bin/perl
  • 2. The second line includes the CGI Perl module and use standard symbols. use CGI qw(:standard); The third line prints the HTML header (text/html by default). print header; The fourth and fifth line prints the HTML title and heading. print start_html(’This is the title’), h1(’This is the heading’); The last line ends the HTML document by printing the </BODY> and </HTML> tags. print end_html; [ Click here to see the effect. | Table of Content ] Redirection Request This program generates a redirection request for the remote browser. #!/usr/local/bin/perl use CGI qw(:standard); print redirect(’http://home.school.net.hk/~hywong/redirect.html’); It will immediately go to the indicated URL, here is, http://home.school.net.hk/~hywong/redirect.html Absolute URLs should be used in redirection requests. Relative URLs will not work correctly. [ Click here to see the effect. | Table of Content ] Unpaired Tags This program reveals the use of unpaired tags including <BR>, <P> and <HR>. #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html(-title=>’This is the title’, -BGCOLOR=>’green’); print (’This is the first line.’); print br; print (’This is the second line.’); print p;
  • 3. print (’This is the second paragraph’); print hr; print (’The background color of this page is GREEN’) print end_html; This lines print out the title of the document and set the background color to green. print start_html(-title=>’This is the title’, -BGCOLOR=>’green’); This line prints out the text "<br>". Print br; This line prints out the text "<p>". Print p; This line prints out the text "<hr>". Print hr; [ Click here to see the effect. | Table of Content ] Paired Tags This program reveals the use of paired tags including <H1>, <B>, <UL> and the like. #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html(-title=>’Paired Tags’, -BGCOLOR=>’yellow’); print h1(’The Use of Paired Tags’); print br; print (’This is an ’, i(’italic’), ’word.’); print p; print ul( li(’1st item of an unordered list’), li(’2nd item of an unordered list’), li(’3rd item of an unordered list’) ); print hr; print (’The background color of this page is ’, em(’YELLOW’)); print p; print a({href=>"http://www.school.net.hk/~hywong/cgipmtut.html#Pair_tag"}, ’GO BACK’); print end_html; This line creates the text "<h1>The Use of Paired Tags</h1>".
  • 4. print h1(’The Use of Paired Tags’); This line creates the text "This is an <i>italic</i> word.". print (’This is an ’, i(’italic’), ’word.’); This line prints out the text: <ul> <li>1st item of an unordered list <li>2nd item of an unordered list <li>3rd item of an unordered list </ul> print ul( li(’1st item of an unordered list’), li(’2nd item of an unordered list’), li(’3rd item of an unordered list’) ); This line creates the text "The background color of this page is <em>YELLOW</em>". print (’The background color of this page is ’, em(’YELLOW’)); This line creates the text "<a href="http://www.school.net.hk/~hywong/cgipmtut.html#Pair_tag>GO BACK</a>". print a({href=>"http://www.school.net.hk/~hywong/cgipmtut.html#Pair_tag"}, ’GO BACK’); [ Click here to see the effect. | Table of Content ] Text Field in CGI Form This program create a CGI form with text fields. #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html(’CGI Form with Text Field’); print h1(’CGI Form with Text Field’); print start_form; print "What is your name?"; print textfield(-name=>’field_name’, -size=>30); print p; print "What is your comment?"; print p; print textarea(-name=>’large_field_name’, -rows=>10, -columns=>50); print p; print submit;
  • 5. print end_form; print hr; if (param()) { print "Your name is ", param(’field_name’), p, "Your comment is: ", param(’large_field_name’), hr; } print a({href=>’http://www.school.net.hk/~hywong/cgipmtut.html#Text_field’}, ’Go Back’); print end_html; This line is used to start a CGI form by creating the <form> tag. print start_form; These lines create a text field of 30 characters. The name of this text field is "field_name". print textfield(-name=>’field_name’, -size=>30); These lines create a large text field with 10 rows and 50 columns. The name of this text field is "large_field_name". print textarea(-name=>’large_field_name’, -rows=>10, -columns=>50); This line creates the submit button. print submit; This line is used to end a CGI form by creating the </form> tag. print end_form; These lines handle the information submitted. if (param()) { print "Your name is ", param(’field_name’), p, "Your comment is: ", param(’large_field_name’), hr; } [ Click here to see the effect. | Table of Content ] Pop Up Menu in CGI Form
  • 6. This program create a CGI form with pop up menu. #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html(’CGI Form with Pop Up Menu’); print h1(’CGI Form with Pop Up Menu’); print start_form; print "What is your favourite color?"; print popup_menu(-name=>’color’, -values=>[’red’,’orange’,’yellow’, ’green’,’blue’,’indigo’,’violet’], -default=>’blue’); print p; print submit(-name=>’submit button’); print ’ ’; print reset; print end_form; print hr; if (param()) { print "Your favourite color is ", param(’color’), hr; } print a({href=>’http://www.school.net.hk/~hywong/cgipmtut.html#Pop_up_menu’}, ’Go Back’); print end_html; This line creates a pop up menu of seven values, while "blue" is the default value. print popup_menu(-name=>’color’, -values=>[’red’,’orange’,’yellow’, ’green’,’blue’,’indigo’,’violet’], -default=>’blue’); This line creates the submit button, with "submit button" as its name. print submit(-name=>’submit button’); This line creates the reset button. print reset; [ Click here to see the effect. | Table of Content ] Checkbox and Radio Button in CGI Form This program create a CGI form with checkboxes and radio buttons. #!/usr/local/bin/perl
  • 7. use CGI qw(:standard); print header; print start_html(’CGI Form with Pop Up Menu’); print h1(’CGI Form with Pop Up Menu’); print start_form; print "What is your favourite color?"; print checkbox_group(-name=>’color’, -values=>[’red ’,’orange ’,’yellow ’, ’green ’,’blue ’,’indigo ’,’violet ’], -default=>[’red ’,’blue ’]); print p; print radio_group(-name=>’color blind’, -values=>[’Yes’,’No’], -default=>’No’); print p; print submit(-name=>’submit button’); print ’ ’; print reset; print end_form; print hr; if (param()) { print "Your favourite color: ", param(’color’), p, "Color blind? ---> ", param(’color blind’), hr; } print a({href=>’http://www.school.net.hk/~hywong/cgipmtut.html#Checkbox’}, ’Go Back’); print end_html; These lines create seven checkboxes, with "red" and "blue" as the default values. print checkbox_group(-name=>’color’, -values=>[’red ’,’orange ’,’yellow ’, ’green ’,’blue ’,’indigo ’,’violet ’], -default=>[’red ’,’blue ’]); These lines create two radio buttons, with "No" as the default value. print radio_group(-name=>’color blind’, -values=>[’Yes’,’No’], -default=>’No’); [ Click here to see the effect. | Table of Content ] This page is brought to you by Wong Ho Yiu Castor. Created on 24th August, 1997. Last modified on 30th August, 1997.