如何将文本框数据传递给 Python CGI 脚本?
将文本框数据传递给 CGI 程序
TEXTAREA 元素用于将多行文本传递给 CGI 程序。
以下是带有 TEXTAREA 框的表单的 HTML 代码示例 -
<form action = "/cgi-bin/textarea.py" method = "post" target = "_blank"> <textarea name = "textcontent" cols = "40" rows = "4"> Type your text here... </textarea> <input type = "submit" value = "Submit" /> </form>
此代码的结果是以下表单 -
Type your text here... Submit
以下是 textarea.cgi 脚本,用于处理 Web 浏览器提供的输入 -
#!/usr/bin/python # 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') else: text_content = "Not entered" print "Content-type:text/html\r\n\r\n" 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>"
广告