A Perl CGI (CGI.pm) textarea example

Here's the source code for a Perl CGI textarea example (a Perl form example). The Perl code below shows how you can display an HTML form with a textarea field, using the Perl CGI.pm module. The first time this script is called it displays a textarea field in a form. After you submit the form, this script displays the text that you entered in the textarea field.

Here's the source code for this Perl CGI.pm script, which generates a textarea in an HTML form:

#!/usr/bin/perl -Tw
#
#  textarea.cgi - demonstrate a simple textarea form using CGI.pm
#
#  Created by alvin alexander, devdaily.com.
#

#-----------------------------------#
#  1. Create a new Perl CGI object  #
#-----------------------------------#

use CGI;
$query = new CGI;

#----------------------------------#
#  2. Print the doctype statement  #
#----------------------------------#

print $query->header;

#----------------------------------------------------#
#  3. Start the HTML doc, and give the page a title  #
#----------------------------------------------------#

print $query->start_html('My textarea.cgi program');

#------------------------------------------------------------#
#  4a.  If the program is called without any params, print   #
#  the textarea form.  Start the form, create the textarea,  #
#  create the submit button, and end the form.               #
#------------------------------------------------------------#

if (!$query->param) {

	print $query->startform;
	print $query->textarea(-name=>'TEXT_AREA',
		-default=>'[Enter anything you want here]',
		-rows=>5,
		-columns=>40);
	print $query->br;
	print $query->submit(-value=>'Submit your text');
	print $query->endform;

} else {

	#----------------------------------------------------------#
	#  4b.  If the program is called with parameters, retrieve #
	#  the 'TEXT_AREA' data into a variable named $yourText,   #
	#  then print that information after an <H3> tag.          #
	#----------------------------------------------------------#

	print $query->h3('Here\'s what I think you entered:');
	$yourText = $query->param('TEXT_AREA');
	print "<BLOCKQUOTE>\n";
	print $yourText;
	print "</BLOCKQUOTE>\n";

}

#-------------------------#
#  5. End the HTML page.  #
#-------------------------#

print $query->end_html;

See this Perl CGI form example in action

You can see this Perl CGI.pm textarea form example in action at this url.