home PYTHONJAVA
 

Ruby CGI method

The following is a list of methods for CGI classes:

serial numbermethod description
1CGI::new([ level="query"])
Create a CGI object. The query can be the following values:
  • query: No HTML generated output

  • html3: HTML3.2

  • html4: HTML4.0 Strict

  • html4Tr: HTML4.0 Transitional

  • html4Fr: HTML4.0 Frameset

2CGI::escape( str)
Use URL encoding to escape strings
3CGI::unescape( str)
Decodes a string encoded by escape().
4CGI::escapeHTML( str)
Encode HTML special characters, including: & < >.
5CGI::unescapeHTML( str)
Decode HTML special characters, including: & < >.
6CGI::escapeElement( str[, element...])
Encode HTML special characters in the specified HTML element.
7CGI::unescapeElement( str, element[, element...])
Decoding HTML special characters in the specified HTML element .
8CGI::parse( query)
Parse the query string and return the key containing the hash = "value pair."
9CGI::pretty( string[, leader=" "])
Returns a neat HTML format. If leader is specified, it will be written to the beginning of each line. leader defaults to two spaces.
10CGI::rfc1123_date( time)
Format the time according to RFC-1123 (for example, Tue, 2 Jun 2008 00:00 :00 GMT).

CGI instantiation method

In the following example, we assign the CGI::new object to the c variable. The method list is as follows:

serial numbermethod description
1c[ name]
returns an array containing the value of the corresponding field named name.
2c.checkbox( name[, value[, check=false]])
C.checkbox( options)

Returns an HTML string that defines the checkbox field. The tag's properties can be passed as a parameter with a hash function.
3c.checkbox_group( name, value...)
C.checkbox_group( options)

> Returns an HTML string that defines the checkbox group. The tag's properties can be passed as a parameter with a hash function.
4c.file_field( name[, size=20[, max]])
C.file_field( options)

Returns the HTML string that defines the file field.
5c.form([ method="post"[, url]]) { ...}
C.form( options)

Returns the HTML string that defines the form form. If a code block is specified, it will be output as the form content. The tag's properties can be passed as a parameter with a hash function.
6c.cookies
Returns a CGI::Cookie object containing the key-value pairs in the cookie.
7c.header([ header])
Returns information about the CGI header. If the header parameter is a hash value, its key-value pair is used to create header information.
8c.hidden( name[, value])
C.hidden( options)

Returns an HTML string that defines a hidden field. The tag's properties can be passed as a parameter with a hash function.
9c.image_button( url[, name[, alt]])
C.image_button( options)

Returns an HTML string that defines an image button. The tag's properties can be passed as a parameter with a hash function.
10c.keys
Returns an array containing the field names of the form.
11c.key?( name)
C.has_key?( name)
C.include?( name)

Returns true if the form contains the specified field name.
12c.multipart_form([ url[, encode]]) { ...}
C.multipart_form( options) { ...}

Returns an HTML string that defines a multimedia form (multipart). The tag's properties can be passed as a parameter with a hash function.
13c.out([ header]) { ...}
Generate HTML and output. Use the output of the block to create a string generated by the body of the page.
14c.params
Returns a hash containing the form field name and value.
15c.params=hash
Set the field name and value to use.
16c.password_field( name[, value[, size=40[, max]]])
C.password_field( options)

Returns an HTML string that defines a password field. The tag's properties can be passed as a parameter with a hash function.
17c.popup_menu( name, value...)
C.popup_menu( options)
C.scrolling_list( name, value...)
C.scrolling_list( options)

Returns an HTML string that defines a popup menu. The tag's properties can be passed as a parameter with a hash function.
18c.radio_button( name[, value[, checked=false]])
C.radio_button( options)

Returns an HTML string that defines a radio field. The tag's properties can be passed as a parameter with a hash function.
19c.radio_group( name, value...)
C.radio_group( options)

Returns an HTML string that defines a radio button group. The tag's properties can be passed as a parameter with a hash function.
20c.reset( name[, value])
C.reset( options)

Returns an HTML string that defines a reset button. The tag's properties can be passed as a parameter with a hash function
21c.text_field( name[, value[, size=40[, max]]])
C.text_field( options)

Returns an HTML string that defines a text field. The tag's properties can be passed as a parameter with a hash function.
22c.textarea( name[, cols=70[, rows=10]]) { ...}
C.textarea( options) { ...}

Returns an HTML string that defines a textarea field. If a block is specified, the string output by the code block will be the content of the textarea. The tag's properties can be passed as a parameter with a hash function.

HTML generation method

You can create HTML tags in the CGI instance using the corresponding HTML tag name, as shown in the following example:

Instance

#!/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 } } } }

CGI object properties

You can use the following properties in your CGI instance:

PropertiesReturn Value
acceptAcceptable MIME Type
accept_charsetAcceptable Character Set
accept_encodingAcceptable Encoding
accept_languageAcceptable Language
auth_typeAcceptable Type
raw_cookieCookie data (original string)
content_lengthContent length
content_typeContent type
FromClient e-mail address
gateway_interfaceCGI version
path_infopath
path_translatedThe converted path
Query_stringQuery String
refererAccess URLs
remote_addrClient Host Address (IP)
remote_hostClient Hostname
remote_identclient name
remote_userAuthenticated Users
request_method Request method (GET, POST, etc.)
script_nameParameter Name
server_nameserver name
server_portServer Port
server_protocolServer Protocol
server_softwareServer Software
user_agentUser agent





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.