Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
CGI::HtmlExtension#text_field
text_field(name = "", value = nil, size = 40, maxlength = nil)
lib/cgi/html.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/cgi/html.rb, line 782
def text_field(name = "", value = nil, size = 40, maxlength = nil)
attributes = if name.kind_of?(String)
{ "TYPE" => "text", "NAME" => name, "VALUE" => value,
"SIZE" => size.to_s }
else
name["TYPE"] = "text"
name
end
attributes["MAXLENGTH"] = maxlength.to_s if maxlength
input(attributes)
end
Generate a text field Input element, as a String.
name is the name of the input field. value is its initial value. size is the size of the input area. maxlength is the maximum length of input accepted.
Alternatively, the attributes can be specified as a hash.
Example
text_field("name") # <INPUT TYPE="text" NAME="name" SIZE="40"> text_field("name", "value") # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40"> text_field("name", "value", 80) # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80"> text_field("name", "value", 80, 200) # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200"> text_field("NAME" => "name", "VALUE" => "value") # <INPUT TYPE="text" NAME="name" VALUE="value">