Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 590 lines (551 sloc) 27.922 kB
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
1 require 'cgi'
0eacdcf @jeremy Use a consistent load path to avoid double requires. Fix some scatter…
jeremy authored
2 require 'action_view/helpers/tag_helper'
76f024a @fxn adds missing requires for Object#blank? and Object#present?
fxn authored
3 require 'active_support/core_ext/object/blank'
330327e @spastorino Call html_escape in ERB::Util module and don't mix it in in the helpers
spastorino authored
4 require 'active_support/core_ext/string/output_safety'
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
5
6 module ActionView
5a0bc2c @rizwanreza Adds title and description where needed.
rizwanreza authored
7 # = Action View Form Tag Helpers
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
8 module Helpers
98dc582 @lifo Merge docrails.
lifo authored
9 # Provides a number of methods for creating form tags that doesn't rely on an Active Record object assigned to the template like
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
10 # FormHelper does. Instead, you provide the names and values manually.
ebf6637 @dhh Added that the html options disabled, readonly, and multiple can all …
dhh authored
11 #
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
12 # NOTE: The HTML options <tt>disabled</tt>, <tt>readonly</tt>, and <tt>multiple</tt> can all be treated as booleans. So specifying
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
13 # <tt>:disabled => true</tt> will give <tt>disabled="disabled"</tt>.
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
14 module FormTagHelper
7b62278 @wycats Make form helpers work with <%=
wycats authored
15 extend ActiveSupport::Concern
16
17 include UrlHelper
18 include TextHelper
19
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored
20 # Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
21 # ActionController::Base#url_for. The method for the form defaults to POST.
22 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
23 # ==== Options
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
24 # * <tt>:multipart</tt> - If set to true, the enctype is set to "multipart/form-data".
98dc582 @lifo Merge docrails.
lifo authored
25 # * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post".
26 # If "put", "delete", or another verb is used, a hidden input with name <tt>_method</tt>
27 # is added to simulate the verb over post.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
28 # * A list of parameters to feed to the URL the form will be posted to.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
29 # * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
c493370 @stefanpenner UJS documentation.
stefanpenner authored
30 # submit behaviour. By default this behaviour is an ajax submit.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
31 #
32 # ==== Examples
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
33 # form_tag('/posts')
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
34 # # => <form action="/posts" method="post">
35 #
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
36 # form_tag('/posts/1', :method => :put)
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
37 # # => <form action="/posts/1" method="put">
38 #
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
39 # form_tag('/upload', :multipart => true)
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
40 # # => <form action="/upload" method="post" enctype="multipart/form-data">
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
41 #
1662aa1 @amatsuda Added a space before "do" keyword
amatsuda authored
42 # <%= form_tag('/posts') do -%>
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
43 # <div><%= submit_tag 'Save' %></div>
44 # <% end -%>
45 # # => <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
46 #
67de0af @jeroenvandijk Updated documentation for block helpers in form_tag_helper.rb
jeroenvandijk authored
47 # <%= form_tag('/posts', :remote => true) %>
c493370 @stefanpenner UJS documentation.
stefanpenner authored
48 # # => <form action="/posts" method="post" data-remote="true">
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
49 #
e407b44 @dhh Made FormTagHelper#form_tag work with blocks, rendering start/end_for…
dhh authored
50 def form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
51 html_options = html_options_for_form(url_for_options, options, *parameters_for_url)
e407b44 @dhh Made FormTagHelper#form_tag work with blocks, rendering start/end_for…
dhh authored
52 if block_given?
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
53 form_tag_in_block(html_options, &block)
e407b44 @dhh Made FormTagHelper#form_tag work with blocks, rendering start/end_for…
dhh authored
54 else
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
55 form_tag_html(html_options)
e407b44 @dhh Made FormTagHelper#form_tag work with blocks, rendering start/end_for…
dhh authored
56 end
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
57 end
58
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
59 # Creates a dropdown selection box, or if the <tt>:multiple</tt> option is set to true, a multiple
60 # choice selection box.
61 #
62 # Helpers::FormOptions can be used to create common select boxes such as countries, time zones, or
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
63 # associated records. <tt>option_tags</tt> is a string containing the option tags for the select box.
64 #
65 # ==== Options
66 # * <tt>:multiple</tt> - If set to true the selection will allow multiple choices.
67 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
68 # * Any other key creates standard HTML attributes for the tag.
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
69 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
70 # ==== Examples
dba196c @lifo Merge docrails
lifo authored
71 # select_tag "people", options_from_collection_for_select(@people, "name", "id")
72 # # <select id="people" name="people"><option value="1">David</option></select>
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored
73 #
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
74 # select_tag "people", "<option>David</option>"
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
75 # # => <select id="people" name="people"><option>David</option></select>
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
76 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
77 # select_tag "count", "<option>1</option><option>2</option><option>3</option><option>4</option>"
78 # # => <select id="count" name="count"><option>1</option><option>2</option>
79 # # <option>3</option><option>4</option></select>
80 #
81 # select_tag "colors", "<option>Red</option><option>Green</option><option>Blue</option>", :multiple => true
dce6ade @akaspick Ensure select_tag#name attribute uses [] when :multiple is true. [#11…
akaspick authored
82 # # => <select id="colors" multiple="multiple" name="colors[]"><option>Red</option>
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
83 # # <option>Green</option><option>Blue</option></select>
84 #
85 # select_tag "locations", "<option>Home</option><option selected="selected">Work</option><option>Out</option>"
86 # # => <select id="locations" name="locations"><option>Home</option><option selected='selected'>Work</option>
87 # # <option>Out</option></select>
88 #
89 # select_tag "access", "<option>Read</option><option>Write</option>", :multiple => true, :class => 'form_input'
dce6ade @akaspick Ensure select_tag#name attribute uses [] when :multiple is true. [#11…
akaspick authored
90 # # => <select class="form_input" id="access" multiple="multiple" name="access[]"><option>Read</option>
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
91 # # <option>Write</option></select>
92 #
93 # select_tag "destination", "<option>NYC</option><option>Paris</option><option>Rome</option>", :disabled => true
94 # # => <select disabled="disabled" id="destination" name="destination"><option>NYC</option>
95 # # <option>Paris</option><option>Rome</option></select>
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
96 def select_tag(name, option_tags = nil, options = {})
dce6ade @akaspick Ensure select_tag#name attribute uses [] when :multiple is true. [#11…
akaspick authored
97 html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
1191e3f @rizwanreza Add :include_blank option for select_tag [#1987 status:resolved]
rizwanreza authored
98 if blank = options.delete(:include_blank)
99 if blank.kind_of?(String)
f86421f @nono content_tag should escape its input
nono authored
100 option_tags = "<option value=\"\">#{blank}</option>".html_safe + option_tags
1191e3f @rizwanreza Add :include_blank option for select_tag [#1987 status:resolved]
rizwanreza authored
101 else
f86421f @nono content_tag should escape its input
nono authored
102 option_tags = "<option value=\"\"></option>".html_safe + option_tags
1191e3f @rizwanreza Add :include_blank option for select_tag [#1987 status:resolved]
rizwanreza authored
103 end
104 end
5fad229 @geekq Fixed that FormTagHelper generates illegal html if name contains e.g.…
geekq authored
105 content_tag :select, option_tags, { "name" => html_name, "id" => sanitize_to_id(name) }.update(options.stringify_keys)
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
106 end
107
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
108 # Creates a standard text field; use these text fields to input smaller chunks of text like a username
109 # or a search query.
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
110 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
111 # ==== Options
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
112 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
113 # * <tt>:size</tt> - The number of visible characters that will fit in the input.
114 # * <tt>:maxlength</tt> - The maximum number of characters that the browser will allow the user to enter.
73dafba @remear Added :placeholder option to ActionView::Helpers::FormTagHelper text_…
remear authored
115 # * <tt>:placeholder</tt> - The text contained in the field by default which is removed when the field receives focus.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
116 # * Any other key creates standard HTML attributes for the tag.
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
117 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
118 # ==== Examples
119 # text_field_tag 'name'
120 # # => <input id="name" name="name" type="text" />
121 #
122 # text_field_tag 'query', 'Enter your search query here'
123 # # => <input id="query" name="query" type="text" value="Enter your search query here" />
124 #
73dafba @remear Added :placeholder option to ActionView::Helpers::FormTagHelper text_…
remear authored
125 # text_field_tag 'search', nil, :placeholder => 'Enter search term...'
126 # # => <input id="search" name="search" placeholder="Enter search term..." type="text" />
127 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
128 # text_field_tag 'request', nil, :class => 'special_input'
129 # # => <input class="special_input" id="request" name="request" type="text" />
130 #
131 # text_field_tag 'address', '', :size => 75
132 # # => <input id="address" name="address" size="75" type="text" value="" />
133 #
134 # text_field_tag 'zip', nil, :maxlength => 5
135 # # => <input id="zip" maxlength="5" name="zip" type="text" />
136 #
137 # text_field_tag 'payment_amount', '$0.00', :disabled => true
138 # # => <input disabled="disabled" id="payment_amount" name="payment_amount" type="text" value="$0.00" />
139 #
140 # text_field_tag 'ip', '0.0.0.0', :maxlength => 15, :size => 20, :class => "ip-input"
141 # # => <input class="ip-input" id="ip" maxlength="15" name="ip" size="20" type="text" value="0.0.0.0" />
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
142 def text_field_tag(name, value = nil, options = {})
5fad229 @geekq Fixed that FormTagHelper generates illegal html if name contains e.g.…
geekq authored
143 tag :input, { "type" => "text", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
7701e64 @NZKoz Add label_tag helper for generating elements. Closes #10802 [DefV]
NZKoz authored
144 end
145
6e69b42 @stephencelis Let label helpers accept blocks.
stephencelis authored
146 # Creates a label element. Accepts a block.
7701e64 @NZKoz Add label_tag helper for generating elements. Closes #10802 [DefV]
NZKoz authored
147 #
392817c @erikstmartin updating link_to and button_to to support :remote => true and other o…
erikstmartin authored
148 # ==== Options
7701e64 @NZKoz Add label_tag helper for generating elements. Closes #10802 [DefV]
NZKoz authored
149 # * Creates standard HTML attributes for the tag.
150 #
151 # ==== Examples
152 # label_tag 'name'
153 # # => <label for="name">Name</label>
154 #
155 # label_tag 'name', 'Your name'
156 # # => <label for="name">Your Name</label>
157 #
158 # label_tag 'name', nil, :class => 'small_label'
159 # # => <label for="name" class="small_label">Name</label>
d18a274 @josevalim Improve previous patch a bit [#3645 state:resolved]
josevalim authored
160 def label_tag(name = nil, content_or_options = nil, options = nil, &block)
161 options = content_or_options if block_given? && content_or_options.is_a?(Hash)
6e69b42 @stephencelis Let label helpers accept blocks.
stephencelis authored
162 options ||= {}
163 options.stringify_keys!
164 options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
d18a274 @josevalim Improve previous patch a bit [#3645 state:resolved]
josevalim authored
165 content_tag :label, content_or_options || name.to_s.humanize, options, &block
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
166 end
167
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
168 # Creates a hidden form input field used to transmit data that would be lost due to HTTP's statelessness or
169 # data that should be hidden from the user.
170 #
171 # ==== Options
172 # * Creates standard HTML attributes for the tag.
173 #
174 # ==== Examples
175 # hidden_field_tag 'tags_list'
176 # # => <input id="tags_list" name="tags_list" type="hidden" />
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
177 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
178 # hidden_field_tag 'token', 'VUBJKB23UIVI1UU1VOBVI@'
179 # # => <input id="token" name="token" type="hidden" value="VUBJKB23UIVI1UU1VOBVI@" />
180 #
181 # hidden_field_tag 'collected_input', '', :onchange => "alert('Input collected!')"
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
182 # # => <input id="collected_input" name="collected_input" onchange="alert('Input collected!')"
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
183 # # type="hidden" value="" />
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
184 def hidden_field_tag(name, value = nil, options = {})
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored
185 text_field_tag(name, value, options.stringify_keys.update("type" => "hidden"))
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
186 end
187
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
188 # Creates a file upload field. If you are using file uploads then you will also need
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
189 # to set the multipart option for the form tag:
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
190 #
9ed919e @fxn revises some <%= in rdoc
fxn authored
191 # <%= form_tag '/upload', :multipart => true do %>
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
192 # <label for="file">File to Upload</label> <%= file_field_tag "file" %>
193 # <%= submit_tag %>
6ef3546 @lifo Merge docrails
lifo authored
194 # <% end %>
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
195 #
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
196 # The specified URL will then be passed a File object containing the selected file, or if the field
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
197 # was left blank, a StringIO object.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
198 #
199 # ==== Options
200 # * Creates standard HTML attributes for the tag.
201 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
202 #
203 # ==== Examples
204 # file_field_tag 'attachment'
205 # # => <input id="attachment" name="attachment" type="file" />
206 #
5f808b8 @dhh Consistently use lowercase instead of camelCase for all JS class name…
dhh authored
207 # file_field_tag 'avatar', :class => 'profile_input'
208 # # => <input class="profile_input" id="avatar" name="avatar" type="file" />
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
209 #
210 # file_field_tag 'picture', :disabled => true
211 # # => <input disabled="disabled" id="picture" name="picture" type="file" />
212 #
213 # file_field_tag 'resume', :value => '~/resume.doc'
214 # # => <input id="resume" name="resume" type="file" value="~/resume.doc" />
215 #
216 # file_field_tag 'user_pic', :accept => 'image/png,image/gif,image/jpeg'
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
217 # # => <input accept="image/png,image/gif,image/jpeg" id="user_pic" name="user_pic" type="file" />
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
218 #
219 # file_field_tag 'file', :accept => 'text/html', :class => 'upload', :value => 'index.html'
220 # # => <input accept="text/html" class="upload" id="file" name="file" type="file" value="index.html" />
df7f345 @dhh Added FormHelper#file_field and FormTagHelper#file_field_tag for crea…
dhh authored
221 def file_field_tag(name, options = {})
064842f Convert boolean form options form the tag_helper. Recloses #809.
Marcel Molina authored
222 text_field_tag(name, nil, options.update("type" => "file"))
df7f345 @dhh Added FormHelper#file_field and FormTagHelper#file_field_tag for crea…
dhh authored
223 end
224
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
225 # Creates a password field, a masked text field that will hide the users input behind a mask character.
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
226 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
227 # ==== Options
228 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
229 # * <tt>:size</tt> - The number of visible characters that will fit in the input.
230 # * <tt>:maxlength</tt> - The maximum number of characters that the browser will allow the user to enter.
231 # * Any other key creates standard HTML attributes for the tag.
232 #
233 # ==== Examples
234 # password_field_tag 'pass'
235 # # => <input id="pass" name="pass" type="password" />
236 #
237 # password_field_tag 'secret', 'Your secret here'
238 # # => <input id="secret" name="secret" type="password" value="Your secret here" />
239 #
240 # password_field_tag 'masked', nil, :class => 'masked_input_field'
241 # # => <input class="masked_input_field" id="masked" name="masked" type="password" />
242 #
243 # password_field_tag 'token', '', :size => 15
244 # # => <input id="token" name="token" size="15" type="password" value="" />
245 #
246 # password_field_tag 'key', nil, :maxlength => 16
247 # # => <input id="key" maxlength="16" name="key" type="password" />
248 #
249 # password_field_tag 'confirm_pass', nil, :disabled => true
250 # # => <input disabled="disabled" id="confirm_pass" name="confirm_pass" type="password" />
251 #
5f808b8 @dhh Consistently use lowercase instead of camelCase for all JS class name…
dhh authored
252 # password_field_tag 'pin', '1234', :maxlength => 4, :size => 6, :class => "pin_input"
253 # # => <input class="pin_input" id="pin" maxlength="4" name="pin" size="6" type="password" value="1234" />
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
254 def password_field_tag(name = "password", value = nil, options = {})
064842f Convert boolean form options form the tag_helper. Recloses #809.
Marcel Molina authored
255 text_field_tag(name, value, options.update("type" => "password"))
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
256 end
257
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
258 # Creates a text input area; use a textarea for longer text inputs such as blog posts or descriptions.
259 #
260 # ==== Options
0230fc9 Disambiguate :size option for text area tag. Closes #8955 [redbeard]
Marcel Molina authored
261 # * <tt>:size</tt> - A string specifying the dimensions (columns by rows) of the textarea (e.g., "25x10").
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
262 # * <tt>:rows</tt> - Specify the number of rows in the textarea
263 # * <tt>:cols</tt> - Specify the number of columns in the textarea
264 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
085db5e @chrismear Make text_area_tag escape contents by default.
chrismear authored
265 # * <tt>:escape</tt> - By default, the contents of the text input are HTML escaped.
266 # If you need unescaped contents, set this to false.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
267 # * Any other key creates standard HTML attributes for the tag.
268 #
269 # ==== Examples
270 # text_area_tag 'post'
271 # # => <textarea id="post" name="post"></textarea>
272 #
273 # text_area_tag 'bio', @user.bio
274 # # => <textarea id="bio" name="bio">This is my biography.</textarea>
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
275 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
276 # text_area_tag 'body', nil, :rows => 10, :cols => 25
277 # # => <textarea cols="25" id="body" name="body" rows="10"></textarea>
278 #
279 # text_area_tag 'body', nil, :size => "25x10"
280 # # => <textarea name="body" id="body" cols="25" rows="10"></textarea>
281 #
282 # text_area_tag 'description', "Description goes here.", :disabled => true
283 # # => <textarea disabled="disabled" id="description" name="description">Description goes here.</textarea>
284 #
285 # text_area_tag 'comment', nil, :class => 'comment_input'
286 # # => <textarea class="comment_input" id="comment" name="comment"></textarea>
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
287 def text_area_tag(name, content = nil, options = {})
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
288 options.stringify_keys!
289
290 if size = options.delete("size")
1dc56ba @dhh Fixed that FormTagHelper#text_area_tag should disregard :size option …
dhh authored
291 options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
292 end
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored
293
085db5e @chrismear Make text_area_tag escape contents by default.
chrismear authored
294 escape = options.key?("escape") ? options.delete("escape") : true
330327e @spastorino Call html_escape in ERB::Util module and don't mix it in in the helpers
spastorino authored
295 content = ERB::Util.html_escape(content) if escape
085db5e @chrismear Make text_area_tag escape contents by default.
chrismear authored
296
d8d38be @jeremy HTML safety: fix textarea with nil content
jeremy authored
297 content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options)
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
298 end
299
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
300 # Creates a check box form input tag.
301 #
302 # ==== Options
303 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
304 # * Any other key creates standard HTML options for the tag.
305 #
306 # ==== Examples
307 # check_box_tag 'accept'
308 # # => <input id="accept" name="accept" type="checkbox" value="1" />
309 #
310 # check_box_tag 'rock', 'rock music'
311 # # => <input id="rock" name="rock" type="checkbox" value="rock music" />
312 #
313 # check_box_tag 'receive_email', 'yes', true
314 # # => <input checked="checked" id="receive_email" name="receive_email" type="checkbox" value="yes" />
315 #
316 # check_box_tag 'tos', 'yes', false, :class => 'accept_tos'
317 # # => <input class="accept_tos" id="tos" name="tos" type="checkbox" value="yes" />
318 #
319 # check_box_tag 'eula', 'accepted', false, :disabled => true
320 # # => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" />
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
321 def check_box_tag(name, value = "1", checked = false, options = {})
5fad229 @geekq Fixed that FormTagHelper generates illegal html if name contains e.g.…
geekq authored
322 html_options = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(options.stringify_keys)
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
323 html_options["checked"] = "checked" if checked
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
324 tag :input, html_options
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
325 end
326
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
327 # Creates a radio button; use groups of radio buttons named the same to allow users to
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
328 # select from a group of options.
329 #
330 # ==== Options
331 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
332 # * Any other key creates standard HTML options for the tag.
333 #
334 # ==== Examples
335 # radio_button_tag 'gender', 'male'
336 # # => <input id="gender_male" name="gender" type="radio" value="male" />
337 #
338 # radio_button_tag 'receive_updates', 'no', true
339 # # => <input checked="checked" id="receive_updates_no" name="receive_updates" type="radio" value="no" />
340 #
341 # radio_button_tag 'time_slot', "3:00 p.m.", false, :disabled => true
342 # # => <input disabled="disabled" id="time_slot_300_pm" name="time_slot" type="radio" value="3:00 p.m." />
343 #
344 # radio_button_tag 'color', "green", true, :class => "color_input"
345 # # => <input checked="checked" class="color_input" id="color_green" name="color" type="radio" value="green" />
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
346 def radio_button_tag(name, value, checked = false, options = {})
c01014a @sikachu Modify the behavior of `radio_button_tag` to use `sanitize_to_id` for…
sikachu authored
347 html_options = { "type" => "radio", "name" => name, "id" => "#{sanitize_to_id(name)}_#{sanitize_to_id(value)}", "value" => value }.update(options.stringify_keys)
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
348 html_options["checked"] = "checked" if checked
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
349 tag :input, html_options
ad1fe7d @dhh Completed FormTagHelper by adding radio_button_tag and select_tag
dhh authored
350 end
351
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
352 # Creates a submit button with the text <tt>value</tt> as the caption.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
353 #
354 # ==== Options
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
355 # * <tt>:confirm => 'question?'</tt> - If present the unobtrusive JavaScript
356 # drivers will provide a prompt with the question specified. If the user accepts,
c493370 @stefanpenner UJS documentation.
stefanpenner authored
357 # the form is processed normally, otherwise no action is taken.
dc4eec1 @lifo Merge docrails:
lifo authored
358 # * <tt>:disabled</tt> - If true, the user will not be able to use this input.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
359 # * <tt>:disable_with</tt> - Value of this parameter will be used as the value for a
360 # disabled version of the submit button when the form is submitted. This feature is
c493370 @stefanpenner UJS documentation.
stefanpenner authored
361 # provided by the unobtrusive JavaScript driver.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
362 # * Any other key creates standard HTML options for the tag.
363 #
364 # ==== Examples
365 # submit_tag
366 # # => <input name="commit" type="submit" value="Save changes" />
367 #
368 # submit_tag "Edit this article"
369 # # => <input name="commit" type="submit" value="Edit this article" />
370 #
371 # submit_tag "Save edits", :disabled => true
372 # # => <input disabled="disabled" name="commit" type="submit" value="Save edits" />
373 #
c493370 @stefanpenner UJS documentation.
stefanpenner authored
374 #
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
375 # submit_tag "Complete sale", :disable_with => "Please wait..."
c493370 @stefanpenner UJS documentation.
stefanpenner authored
376 # # => <input name="commit" data-disable-with="Please wait..."
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
377 # # type="submit" value="Complete sale" />
378 #
379 # submit_tag nil, :class => "form_submit"
380 # # => <input class="form_submit" name="commit" type="submit" />
381 #
5f808b8 @dhh Consistently use lowercase instead of camelCase for all JS class name…
dhh authored
382 # submit_tag "Edit", :disable_with => "Editing...", :class => "edit_button"
383 # # => <input class="edit_button" data-disable_with="Editing..."
64092de @fxn Improve documentation coverage and markup
fxn authored
384 # # name="commit" type="submit" value="Edit" />
c493370 @stefanpenner UJS documentation.
stefanpenner authored
385 #
386 # submit_tag "Save", :confirm => "Are you sure?"
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored
387 # # => <input name='commit' type='submit' value='Save'
c493370 @stefanpenner UJS documentation.
stefanpenner authored
388 # data-confirm="Are you sure?" />
389 #
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
390 def submit_tag(value = "Save changes", options = {})
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
391 options.stringify_keys!
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
392
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
393 if disable_with = options.delete("disable_with")
e7f0d37 @jeremy Remove superfluous condition
jeremy authored
394 options["data-disable-with"] = disable_with
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
395 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
396
123f5a3 @dhh Added :confirm option to submit_tag (closes #11415) [miloops]
dhh authored
397 if confirm = options.delete("confirm")
0c824e3 @spastorino Refactor a bit this code to add data-confirm and data-disable-with
spastorino authored
398 options["data-confirm"] = confirm
123f5a3 @dhh Added :confirm option to submit_tag (closes #11415) [miloops]
dhh authored
399 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
400
00541f2 @dhh Added :disable_with option to FormTagHelper#submit_tag to allow for e…
dhh authored
401 tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
402 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
403
ecb0e39 @dhh Added additional documentation to FormTagHelper #1788 [jon@instance-d…
dhh authored
404 # Displays an image which when clicked will submit the form.
405 #
8b2266a @fxn image_path -> path_to_image in a couple of places, plus motivation fo…
fxn authored
406 # <tt>source</tt> is passed to AssetTagHelper#path_to_image
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
407 #
408 # ==== Options
b141624 @pyrat Added image_submit_tag confirm option [status:committed #784]
pyrat authored
409 # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
410 # prompt with the question specified. If the user accepts, the form is
411 # processed normally, otherwise no action is taken.
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
412 # * <tt>:disabled</tt> - If set to true, the user will not be able to use this input.
413 # * Any other key creates standard HTML options for the tag.
414 #
415 # ==== Examples
416 # image_submit_tag("login.png")
417 # # => <input src="/images/login.png" type="image" />
418 #
b18585f @NZKoz Fix syntax errors in the documentation for image submit tag. Closes …
NZKoz authored
419 # image_submit_tag("purchase.png", :disabled => true)
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
420 # # => <input disabled="disabled" src="/images/purchase.png" type="image" />
421 #
5f808b8 @dhh Consistently use lowercase instead of camelCase for all JS class name…
dhh authored
422 # image_submit_tag("search.png", :class => 'search_button')
423 # # => <input class="search_button" src="/images/search.png" type="image" />
b00e6a9 @dhh Massive documentation update for all helpers (closes #8223, #8177, #8…
dhh authored
424 #
5f808b8 @dhh Consistently use lowercase instead of camelCase for all JS class name…
dhh authored
425 # image_submit_tag("agree.png", :disabled => true, :class => "agree_disagree_button")
426 # # => <input class="agree_disagree_button" disabled="disabled" src="/images/agree.png" type="image" />
d2fb072 @dhh Added FormTagHelper#image_submit_tag for making submit buttons that u…
dhh authored
427 def image_submit_tag(source, options = {})
b141624 @pyrat Added image_submit_tag confirm option [status:committed #784]
pyrat authored
428 options.stringify_keys!
429
430 if confirm = options.delete("confirm")
0c824e3 @spastorino Refactor a bit this code to add data-confirm and data-disable-with
spastorino authored
431 options["data-confirm"] = confirm
b141624 @pyrat Added image_submit_tag confirm option [status:committed #784]
pyrat authored
432 end
433
b1c3fc2 @NZKoz Rename image_path path_to_image to avoid conflicting with named route…
NZKoz authored
434 tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys)
d2fb072 @dhh Added FormTagHelper#image_submit_tag for making submit buttons that u…
dhh authored
435 end
0e6c8e5 @NZKoz Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
NZKoz authored
436
437 # Creates a field set for grouping HTML form elements.
438 #
439 # <tt>legend</tt> will become the fieldset's title (optional as per W3C).
8c105ee @akaspick Add options to field_set_tag
akaspick authored
440 # <tt>options</tt> accept the same values as tag.
0e6c8e5 @NZKoz Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
NZKoz authored
441 #
5b92dcb Merge docrails
lifo authored
442 # ==== Examples
67de0af @jeroenvandijk Updated documentation for block helpers in form_tag_helper.rb
jeroenvandijk authored
443 # <%= field_set_tag do %>
0e6c8e5 @NZKoz Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
NZKoz authored
444 # <p><%= text_field_tag 'name' %></p>
445 # <% end %>
446 # # => <fieldset><p><input id="name" name="name" type="text" /></p></fieldset>
447 #
67de0af @jeroenvandijk Updated documentation for block helpers in form_tag_helper.rb
jeroenvandijk authored
448 # <%= field_set_tag 'Your details' do %>
0e6c8e5 @NZKoz Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
NZKoz authored
449 # <p><%= text_field_tag 'name' %></p>
450 # <% end %>
451 # # => <fieldset><legend>Your details</legend><p><input id="name" name="name" type="text" /></p></fieldset>
8c105ee @akaspick Add options to field_set_tag
akaspick authored
452 #
67de0af @jeroenvandijk Updated documentation for block helpers in form_tag_helper.rb
jeroenvandijk authored
453 # <%= field_set_tag nil, :class => 'format' do %>
8c105ee @akaspick Add options to field_set_tag
akaspick authored
454 # <p><%= text_field_tag 'name' %></p>
455 # <% end %>
456 # # => <fieldset class="format"><p><input id="name" name="name" type="text" /></p></fieldset>
457 def field_set_tag(legend = nil, options = nil, &block)
0e6c8e5 @NZKoz Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
NZKoz authored
458 content = capture(&block)
7b62278 @wycats Make form helpers work with <%=
wycats authored
459 output = tag(:fieldset, options, true)
460 output.safe_concat(content_tag(:legend, legend)) unless legend.blank?
461 output.concat(content)
462 output.safe_concat("</fieldset>")
0e6c8e5 @NZKoz Add fieldset_tag for generating fieldsets, closes #9477. [djanowski]
NZKoz authored
463 end
f8730e5 @dhh Added all the new HTML5 form types as individual form tag methods (se…
dhh authored
464
465 # Creates a text field of type "search".
466 #
467 # ==== Options
468 # * Accepts the same options as text_field_tag.
469 def search_field_tag(name, value = nil, options = {})
470 text_field_tag(name, value, options.stringify_keys.update("type" => "search"))
471 end
472
473 # Creates a text field of type "tel".
474 #
475 # ==== Options
476 # * Accepts the same options as text_field_tag.
477 def telephone_field_tag(name, value = nil, options = {})
478 text_field_tag(name, value, options.stringify_keys.update("type" => "tel"))
479 end
480 alias phone_field_tag telephone_field_tag
481
482 # Creates a text field of type "url".
483 #
484 # ==== Options
485 # * Accepts the same options as text_field_tag.
486 def url_field_tag(name, value = nil, options = {})
487 text_field_tag(name, value, options.stringify_keys.update("type" => "url"))
488 end
489
490 # Creates a text field of type "email".
491 #
492 # ==== Options
493 # * Accepts the same options as text_field_tag.
494 def email_field_tag(name, value = nil, options = {})
495 text_field_tag(name, value, options.stringify_keys.update("type" => "email"))
496 end
497
498 # Creates a number field.
499 #
500 # ==== Options
501 # * <tt>:min</tt> - The minimum acceptable value.
502 # * <tt>:max</tt> - The maximum acceptable value.
503 # * <tt>:in</tt> - A range specifying the <tt>:min</tt> and
504 # <tt>:max</tt> values.
505 # * <tt>:step</tt> - The acceptable value granularity.
506 # * Otherwise accepts the same options as text_field_tag.
507 #
508 # ==== Examples
509 # number_field_tag 'quantity', nil, :in => 1...10
510 # => <input id="quantity" name="quantity" min="1" max="9" />
511 def number_field_tag(name, value = nil, options = {})
512 options = options.stringify_keys
513 options["type"] ||= "number"
514 if range = options.delete("in") || options.delete("within")
515 options.update("min" => range.min, "max" => range.max)
516 end
517 text_field_tag(name, value, options)
518 end
519
520 # Creates a range form element.
521 #
522 # ==== Options
523 # * Accepts the same options as number_field_tag.
524 def range_field_tag(name, value = nil, options = {})
525 number_field_tag(name, value, options.stringify_keys.update("type" => "range"))
526 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
527
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
528 private
529 def html_options_for_form(url_for_options, options, *parameters_for_url)
b1cfced @spastorino Change returning with tap
spastorino authored
530 options.stringify_keys.tap do |html_options|
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
531 html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart")
cba1460 @fxn url_for no longer escapes HTML, the :escape option is also gone
fxn authored
532 # The following URL is unescaped, this is just a hash of options, and it is the
533 # responsability of the caller to escape all the values.
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
534 html_options["action"] = url_for(url_for_options, *parameters_for_url)
6fe424a @wycats Small typo
wycats authored
535 html_options["accept-charset"] = "UTF-8"
a9e89e8 @stevestmartin add :remote option to form_tag
stevestmartin authored
536 html_options["data-remote"] = true if html_options.delete("remote")
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
537 end
538 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
539
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
540 def extra_tags_for_form(html_options)
25215d7 @wycats Fix several known web encoding issues:
wycats authored
541 snowman_tag = tag(:input, :type => "hidden",
483b60b @wycats Revert "It's snowing!"
wycats authored
542 :name => "utf8", :value => "&#x2713;".html_safe)
25215d7 @wycats Fix several known web encoding issues:
wycats authored
543
544 method = html_options.delete("method").to_s
545
546 method_tag = case method
ccf9577 @dolzenko Fix a bunch of minor spelling mistakes
dolzenko authored
547 when /^get$/i # must be case-insensitive, but can't use downcase as might be nil
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
548 html_options["method"] = "get"
549 ''
550 when /^post$/i, "", nil
551 html_options["method"] = "post"
25215d7 @wycats Fix several known web encoding issues:
wycats authored
552 token_tag
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
553 else
554 html_options["method"] = "post"
25215d7 @wycats Fix several known web encoding issues:
wycats authored
555 tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
556 end
25215d7 @wycats Fix several known web encoding issues:
wycats authored
557
558 tags = snowman_tag << method_tag
559 content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline')
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
560 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
561
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
562 def form_tag_html(html_options)
563 extra_tags = extra_tags_for_form(html_options)
4cbb9db For performance reasons, you can no longer call html_safe! on Strings…
Yehuda Katz authored
564 (tag(:form, html_options, true) + extra_tags).html_safe
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
565 end
72f93b5 @jeremy Check whether blocks are called from erb using a special __in_erb_tem…
jeremy authored
566
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
567 def form_tag_in_block(html_options, &block)
568 content = capture(&block)
7b62278 @wycats Make form helpers work with <%=
wycats authored
569 output = ActiveSupport::SafeBuffer.new
570 output.safe_concat(form_tag_html(html_options))
571 output << content
572 output.safe_concat("</form>")
1ff8450 @technoweenie Refactor #form_tag to allow easy extending. [Rick]
technoweenie authored
573 end
4e3ed5b @technoweenie Merge csrf_killer plugin into rails. Adds RequestForgeryProtection m…
technoweenie authored
574
575 def token_tag
5edc81d @technoweenie Allow ability to disable request forgery protection, disable it in te…
technoweenie authored
576 unless protect_against_forgery?
4e3ed5b @technoweenie Merge csrf_killer plugin into rails. Adds RequestForgeryProtection m…
technoweenie authored
577 ''
578 else
c619003 @technoweenie Rename some RequestForgeryProtection methods. The class method is no…
technoweenie authored
579 tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
4e3ed5b @technoweenie Merge csrf_killer plugin into rails. Adds RequestForgeryProtection m…
technoweenie authored
580 end
581 end
5fad229 @geekq Fixed that FormTagHelper generates illegal html if name contains e.g.…
geekq authored
582
583 # see http://www.w3.org/TR/html4/types.html#type-name
584 def sanitize_to_id(name)
585 name.to_s.gsub(']','').gsub(/[^-a-zA-Z0-9:.]/, "_")
586 end
967339e @dhh Added FormTagHelper that provides a number of methods for creating fo…
dhh authored
587 end
588 end
589 end
Something went wrong with that request. Please try again.