How to pass Text Area Data to Python CGI script?

PythonServer Side ProgrammingProgramming

Passing Text Area Data to CGI Program

TEXTAREA element is used when multiline text has to be passed to the CGI Program.

Here is example HTML code for a form with a TEXTAREA box −

<form action = "/cgi-bin/" method = "post" target = "_blank">
<textarea name = "textcontent" cols = "40" rows = "4">
Type your text here...
<input type = "submit" value = "Submit" />

The result of this code is the following form −

Type your text here...

Below is textarea.cgi script to handle input given by web browser −

# Import modules for CGI handling
import cgi, cgitb
# Create instance of FieldStorage
form = cgi.FieldStorage()
# Get data from fields
if form.getvalue('textcontent'):
   text_content = form.getvalue('textcontent')
   text_content = "Not entered"
print "Content-type:text/html\r
" print "<html>" print "<head>"; print "<title>Text Area - Fifth CGI Program</title>" print "</head>" print "<body>" print "<h2> Entered Text Content is %s</h2>" % text_content print "</body>"
Updated on 16-Jun-2020 12:18:43