May 12, 2021 Ruby
The following is a list of methods for CGI classes:
Serial number | Method description |
---|---|
1 |
CGI::new([ level="query"])
Create a CGI object. Q uery can be the following value:
|
2 |
CGI::escape( str)
Use URL encoding to escape strings |
3 |
CGI::unescape( str)
Decode strings encoded by escape(). |
4 |
CGI::escapeHTML( str)
Encode HTML special characters, including: and slt; |
5 |
CGI::unescapeHTML( str)
Decode HTML special characters, including: and slt; |
6 |
CGI::escapeElement( str[, element...])
Encode HTML special characters in the specified HTML element. |
7 |
CGI::unescapeElement( str, element[, element...])
Decode HTML special characters in the specified HTML element. |
8 |
CGI::parse( query)
Resolve the query string and return the key value pair that contains the hash. |
9 |
CGI::pretty( string[, leader=" "])
Return to the neat HTML format. I f a leader is specified, it is written to the beginning of each line. The leader default is two spaces. |
10 |
CGI::rfc1123_date( time)
Format the time according to RFC-1123 (e.g., Tue, 2 Jun 2008 00:00:00 GMT). |
In the following example, we assign CGI::new objects to the c variable, and the list of methods is as follows:
Serial number | Method description |
---|---|
1 |
c[ name]
Returns an array that contains a value for the corresponding field name name. |
2 |
c.checkbox( name[, value[, check=false]])
c.checkbox( options) Returns an HTML string to define the checkbox field. The properties of a label can be passed as an argument by a hash function. |
3 |
c.checkbox_group( name, value...)
c.checkbox_group( options) Return html strings to define checkbox groups. The properties of a label can be passed as an argument by a hash function. |
4 |
c.file_field( name[, size=20[, max]])
c.file_field( options) Returns the HTML string that defines the file field. |
5 |
c.form([ method="post"[, url]]) { ...}
c.form( options) Returns the HTML string that defines the form form. I f a block of code is specified, it is output as form content. The properties of a label can be passed as an argument by a hash function. |
6 |
c.cookies
Return CGI:: The cookie object contains the key value pair in the cookie. |
7 |
c.header([ header])
Returns the information for the CGI header. If the header parameter is hashed, its key-value pair is used to create header information. |
8 |
c.hidden( name[, value])
c.hidden( options) Returns an HTML string that defines a hidden field. The properties of a label can be passed as an argument by a hash function. |
9 |
c.image_button( url[, name[, alt]])
c.image_button( options) Returns the HTML string that defines an image button. The properties of a label can be passed as an argument by a hash function. |
10 |
c.keys
Returns an array that contains the field name of the form. |
11 |
c.key?
( name)
c.has_key? ( name) c.include? ( name) True if the form contains the specified field name. |
12 |
c.multipart_form([ url[, encode]]) { ...}
c.multipart_form( options) { ...} Returns the HTML string that defines a multimedia form . The properties of a label can be passed as an argument by a hash function. |
13 |
c.out([ header]) { ...}
Generate HTML and output. Use the output of the block to create a string generated by the body of the page. |
14 |
c.params
Returns a hash that contains the form field name and value. |
15 |
c.params= hash
The setting uses the field name and value. |
16 |
c.password_field( name[, value[, size=40[, max]]])
c.password_field( options) Returns the HTML string that defines a password field. The properties of a label can be passed as an argument by a hash function. |
17 |
c.popup_menu( name, value...)
c.popup_menu( options) c.scrolling_list( name, value...) c.scrolling_list( options) Returns the HTML string that defines a pop-up menu. The properties of a label can be passed as an argument by a hash function. |
18 |
c.radio_button( name[, value[, checked=false]])
c.radio_button( options) Returns the HTML string that defines a radio field. The properties of a label can be passed as an argument by a hash function. |
19 |
c.radio_group( name, value...)
c.radio_group( options) Returns the HTML string that defines a group of radio buttons. The properties of a label can be passed as an argument by a hash function. |
20 |
c.reset( name[, value])
c.reset( options) Returns the HTML string that defines a reset button. The properties of a label can be passed as an argument by a hash function |
21 |
c.text_field( name[, value[, size=40[, max]]])
c.text_field( options) Returns the HTML string that defines a text field. The properties of a label can be passed as an argument by a hash function. |
22 |
c.textarea( name[, cols=70[, rows=10]]) { ...}
c.textarea( options) { ...} Returns the HTML string that defines a textarea field. I f a block is specified, the string output of the block will be the content of textarea. The properties of a label can be passed as an argument by a hash function. |
You can then use the appropriate HTML tag name in the CGI instance to create the HTML tag, as follows:
#!/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 then use the following properties in the CGI instance:
Property | Returns a value |
---|---|
accept | Acceptable MIME type |
accept_charset | The acceptable character set |
accept_encoding | Acceptable coding |
accept_language | Acceptable language |
auth_type | The type that is acceptable |
raw_cookie | Cookie data (original string) |
content_length | Content length (Content length) |
content_type | Content type |
From | Client e-mail address |
gateway_interface | CGI version |
path_info | Path |
path_translated | The converted path |
Query_string | The query string |
referer | Visit the URL before |
remote_addr | Client Host Address (IP) |
remote_host | The client host name |
remote_ident | The client name |
remote_user | Authenticated users |
request_method | Request method (GET, POST, etc.). ) |
script_name | The name of the argument |
server_name | The name of the server |
server_port | The server port |
server_protocol | The server protocol |
server_software | Server software |
user_agent | User Agent |