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_ |
Add a field with field_name and value |
| field | Fetch the first field whose name is equal to field_name |
| has_ |
Returns whether or not the form contains a field with field_name |
| has_ |
Alias for #has_field? |
| has_ |
|
| keys | |
| method_ |
Treat form fields like accessors. |
| new | |
| set_ |
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 | |
<code/>and<pre/>for code samples.