Module: ActionView::Helpers::FormTagHelper

Module | ActionView::Helpers::FormTagHelper
In: | lib/action_view/helpers/form_tag_helper.rb

Provides a number of methods for creating form tags that doesn‘t rely on conventions with an object assigned to the template like FormHelper does. With the FormTagHelper, you provide the names and values yourself.

NOTE: The html options disabled, readonly, and multiple can all be treated as booleans. So specifying `:disabled => true` will give `disabled="disabled"`.

### Methods

check_box_tag end_form_tag file_field_tag form_tag hidden_field_tag image_submit_tag password_field_tag radio_button_tag select_tag start_form_tag submit_tag text_area_tag text_field_tag

### Public Instance methods

check_box_tag(name, value = "1", checked = false, options = {})

Creates a check box.

end_form_tag()

Outputs "</form>"

file_field_tag(name, options = {})

Creates a file upload field.

If you are using file uploads then you will also need to set the multipart option for the form:

      <%= form_tag { :action => "post" }, { :multipart => true } %>
        <label for="file">File to Upload</label> <%= file_field_tag "file" %>
        <%= submit_tag %>
      <%= end_form_tag %>

The specified URL will then be passed a File object containing the selected file, or if the field was left blank, a StringIO object.

form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)

Starts a form tag that points the action to an url configured with `url_for_options` just like ActionController::Base#url_for. The method for the form defaults to POST.

Options:

- `:multipart` - If set to true, the enctype is set to "multipart/form-data".
- `:method` - The method to use when submitting the form, usually either "get" or "post".

hidden_field_tag(name, value = nil, options = {})

Creates a hidden field.

Takes the same options as text_field_tag

image_submit_tag(source, options = {})

Displays an image which when clicked will submit the form.

`source` is passed to AssetTagHelper#image_path

password_field_tag(name = "password", value = nil, options = {})

Creates a password field.

Takes the same options as text_field_tag

radio_button_tag(name, value, checked = false, options = {})

Creates a radio button.

select_tag(name, option_tags = nil, options = {})

Creates a dropdown selection box, or if the `:multiple` option is set to true, a multiple choice selection box.

Helpers::FormOptions can be used to create common select boxes such as countries, time zones, or associated records.

`option_tags` is a string containing the option tags for the select box:

      # Outputs <select id="people" name="people"><option>David</option></select>
      select_tag "people", "<option>David</option>"

Options:

- `:multiple` - If set to true the selection will allow multiple choices.

start_form_tag(url_for_options = {}, options = {}, *parameters_for_url, &proc)

Alias for form_tag

submit_tag(value = "Save changes", options = {})

Creates a submit button with the text `value` as the caption. If options contains a pair with the key of "disable_with", then the value will be used to rename a disabled version of the submit button.

text_area_tag(name, content = nil, options = {})

Creates a text input area.

Options:

- `:size` - A string specifying the dimensions of the textarea.

        # Outputs <textarea name="body" id="body" cols="25" rows="10"></textarea>
        <%= text_area_tag "body", nil, :size => "25x10" %>

text_field_tag(name, value = nil, options = {})

Creates a standard text field.

Options:

- `:disabled` - If set to true, the user will not be able to use this input.
- `:size` - The number of visible characters that will fit in the input.
- `:maxlength` - The maximum number of characters that the browser will allow the user to enter.

A hash of standard HTML options for the tag.

[Validate]