English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The following is a list of methods for the CGI class:
CGI instantiation method | In the following examples, we assign the object of CGI::new to the variable c, and the method list is as follows: |
---|---|
1 | CGI::new([ level="query"]) Create CGI objects. query can be one of the following values:
|
2 | CGI::escape( str) Use URL encoding to escape strings |
3 | CGI::unescape( str) Decode strings encoded with escape(). |
4 | CGI::escapeHTML( str) Encode HTML special characters, including: & < >. |
5 | CGI::unescapeHTML( str) Decode HTML special characters, including: & < >. |
6 | CGI::escapeElement( str[, element...]) Encode HTML special characters within specified HTML elements. |
7 | CGI::unescapeElement( str, element[, element...]) 在指定的 HTML 元素中解码 HTML 特殊字符。 |
8 | CGI::unescapeElement(str, element[, element...]) Decode HTML special characters in the specified HTML element. |
9 | CGI::parse(query) Parse the query string and return a hash containing key=>value pairs. Returns neatly formatted HTML. If specified CGI::pretty(string[, leader=" "]) Returns neatly formatted HTML. If specified which will be written at the beginning of each line. |
10 | leader1123The default value is two spaces. CGI::rfc-1123 _date(time) 2 According to RFC 2To format time (for example, Tue,8 Jun |
00:00:00 GMT).
CGI instantiation method | In the following examples, we assign the object of CGI::new to the variable c, and the method list is as follows: |
---|---|
1 | Serial number Method description c[name] Returns an array containing the corresponding field name |
2 | name The value. Returns an HTML string for defining a checkbox field. The tag attributes can be passed as a hash function parameter. |
3 | c.checkbox_group(name, value...) c.checkbox_group(options) >Returns an HTML string for defining a checkbox group. The tag attributes can be passed as a hash function parameter. |
4 | c.file_field(name[, size=20[, max]]) c.file_field(options) Returns the HTML string defined by the file field. |
5 | c.form([method="post"[, url]]) { ...} c.form(options) Returns the HTML string defined by the form. If a code block is specified, it will be output as the form content. The tag attributes can be passed as a hash function parameter. |
6 | c.cookies Returns the CGI::Cookie object, which contains key-value pairs in the cookie. |
7 | c.header([header]) Returns information of the CGI header. If the header parameter is a hash, the key - Value pairs used to create header information. |
8 | c.hidden(name[, value]) c.hidden(options) Returns an HTML string for defining a hidden field. The tag attributes can be passed as a hash function parameter. |
9 | c.image_button( url[, name[, alt]]) c.image_button( options) Returns an HTML string for defining an image button. The tag attributes can be passed as a hash function parameter. |
10 | c.keys Returns an array containing the field names of the form. |
11 | c.key?( name) c.has_key?( name) c.include?( name) Returns true if the form contains the specified field name. |
12 | c.multipart_form([ url[, encode]]) { ...} c.multipart_form( options) { ...} Returns an HTML string for defining a multimedia form (multipart). The tag attributes can be passed as a hash function parameter. |
13 | c.out([ header]) { ...} Generates HTML and outputs. Use the string generated by the block output to create the main content of the page. |
14 | c.params Returns a hash containing the form field names and values. |
15 | c.params= hash Sets the field name and value to be used. |
16 | c.password_field( name[, value[, size=40[, max]] c.password_field( options) Returns an HTML string for defining a password field. The tag attributes can be passed as a hash function parameter. |
17 | c.popup_menu( name, value...) c.popup_menu( options) c.scrolling_list( name, value...) c.scrolling_list( options) Returns an HTML string for defining a dropdown menu. The tag attributes can be passed as a hash function parameter. |
18 | c.radio_button( name[, value[, checked=false]]) c.radio_button( options) Returns an HTML string for defining a radio field. The tag attributes can be passed as a hash function parameter. |
19 | c.radio_group( name, value...) c.radio_group( options) Returns an HTML string for defining a radio button group. The tag attributes can be passed as a hash function parameter. |
20 | c.reset( name[, value])}} c.reset( options) Returns a string of HTML to define a reset button. The tag attributes can be passed as a hash function as a parameter. |
21 | c.text_field( name[, value[, size=40[, max]] c.text_field( options) Returns a string of HTML to define a text field. The tag attributes can be passed as a hash function as a parameter. |
22 | c.textarea( name[, cols=70[, rows=10]] { ...} c.textarea( options) { ...} Returns a string of HTML to define a textarea field. If a block is specified, the string output by the code block will be used as the content of the textarea. The tag attributes can be passed as a hash function as a parameter. |
You can use the corresponding HTML tag names in the CGI example to create HTML tags, for example:
#!/usr/bin/ruby require "cgi" cgi = CGI.new("html4") cgi.out{ cgi.html{ cgi.head{ "\n"+cgi.title{"This Is a Test"} } + cgi.body{ "\n"+ cgi.form{"\n"+ cgi.hr + cgi.h1 { "A Form: " } + "\n"+ cgi.textarea("get_text") +"\n"+ cgi.br + cgi.submit } } } }
You can use the following properties in the CGI example:
Properties | Return value |
---|---|
accept | Acceptable MIME types |
accept_charset | Acceptable character sets |
accept_encoding | Acceptable encodings |
accept_language | Acceptable languages |
auth_type | Acceptable types |
raw_cookie | Cookie data (original string) |
content_length | Content length |
content_type | Content type |
From | Client e-mail address |
gateway_interface | CGI Version |
path_info | Path |
path_translated | Translated Path |
Query_string | Query String |
referer | Previous Visited URL |
remote_addr | Client Host Address (IP) |
remote_host | Client Hostname |
remote_ident | Client Name |
remote_user | Authenticated User |
request_method | Request Method (GET, POST, etc.) |
script_name | Parameter Name |
server_name | Server Name |
server_port | Server Port |
server_protocol | Server Protocol |
server_software | Server Software |
user_agent | User Agent (User agent) |