Class

Form

Extends:

Contents:

Synopsis

This class encapsulates a form parsed out of an HTML page. Each type of input fields available in a form can be accessed through this object. See GlobalForm for more methods.

Example

Find a form and print out its fields

form = page.forms.first # => WWW::Mechanize::Form
form.fields.each { |f| puts f.name }

Set the input field ‘name’ to "Aaron"

form['name'] = 'Aaron'
puts form['name']
Public Attributes
node
page
Public Methods
[] Fetch the value of the first input field with the name passed in
[]= Set the value of the first input field with the name passed in
add_field! Add a field with field_name and value
field Fetch the first field whose name is equal to field_name
has_field? Returns whether or not the form contains a field with field_name
has_key? Alias for #has_field?
has_value?
keys
method_missing Treat form fields like accessors.
new
set_fields This method sets multiple fields on the form. It takes a list of field name, value pairs. If there is more than one field found with the same name, this method will set the first one found. If you want to set the value of a duplicate field, use a value which is an Array with the second value of the array as the index in to the form. The index is zero based. For example, to set the second field named ‘foo’, you could do the following:
submit Submit this form with the button passed in
values
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.