Database Reference
In-Depth Information
print
start_form
(
-
action
=>
url
(),
-
method
=>
"post"
);
# ... generate form elements here ...
print
end_form
();
start_form()
supplies a default request method of
post
. You can omit the
method
argument if you're constructing a
post
form.
Ruby
In Ruby scripts, create a
cgi
object, and use its
form
method to generate a form. The
method arguments provide the
<form>
tag attributes, and the block following the meth‐
od call provides the form content. To get the script pathname, use the
SCRIPT_NAME
member of the
ENV
hash:
cgi
.
out
{
cgi
.
form
(
"action"
=>
ENV
[
"SCRIPT_NAME"
]
,
"method"
=>
"post"
) {
# ... generate form elements here ...
}
}
The
form
method supplies a default request method of
post
. You can omit the
method
argument if you're constructing a
post
form.
The script pathname is also available from the
cgi.script_name
method.
PHP
PHP scripts access the script pathname as the
PHP_SELF
member of the
$_SERVER
array,
which is a “superglobal” array (accessible in any scope without being declared as global).
Scripts can obtain their own pathname and use it to generate a form as follows:
print
(
'<form action="'
.
$_SERVER
[
'PHP_SELF'
]
.
'" method="post">'
);
# ... generate form elements here ...
print
(
'</form>'
);
Python
Python scripts get the script pathname by importing the
os
module and accessing the
SCRIPT_NAME
member of the
os.environ
object:
import
os
print
(
'<form action="
%s
" method="post">'
%
os
.
environ
[
'SCRIPT_NAME'
])
# ... generate form elements here ...
print
(
'</form>'
)
Java
In JSP pages, the request path is available through the implicit
request
object provided
by the JSP processor. Use that object's
getRequestURI()
method as follows: