Module: ActionView::Helpers::FormTagHelper
- Defined in:
- lib/mead_captcha/form_tag_helper.rb
Instance Method Summary collapse
-
#mead_honeypot_tag(options = {}, tag: nil, name: nil, value: nil, &block) ⇒ Object
Creates a honeypot on forms By default it creates a <div> that wraps around a <label> and <input type=“text”>.
-
#mead_obfuscate_tag(name, &block) ⇒ Object
Obfuscates the name of a field and provides the name to a block.
Instance Method Details
#mead_honeypot_tag(options = {}, tag: nil, name: nil, value: nil, &block) ⇒ Object
Creates a honeypot on forms By default it creates a <div> that wraps around a <label> and <input type=“text”>. Can also use it as a content_tag that will allow you to do more exotic layouts.
Examples
honeypot_field_tag
# => <div> # <label for=“pseudo_random_field_name”> # <input type=“text” name=“pseudo_random_field_name” id=“pseudo_random_field_name”> # </div>
honeypot_field_tag(:label) do |name|
check_box_tag(:do_not_check, name, false, class: 'mead-input-attributes')
# => <label class=“mead-label-attributes”> # <input id=“name”, name=“name”, type=“checkbox”, value=“false”> # </label>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mead_captcha/form_tag_helper.rb', line 25 def mead_honeypot_tag( = {}, tag: nil, name: nil, value: nil, &block) = .stringify_keys = .delete('label_options') || {} = .delete('wrapper_options') || {} name ||= mead_field_name tag ||= :div if block_given? content_tag(tag, , &block) else label = label_tag(name, name.titleize, mead_label_attributes.merge()) field = text_field_tag(name, value, mead_input_attributes.merge()) content_tag(tag, label + field, mead_wrapper_attributes.merge()) end end |
#mead_obfuscate_tag(name, &block) ⇒ Object
Obfuscates the name of a field and provides the name to a block.
Examples mead_obfuscate_tag(:first_name) do |first_name|
label_tag first_name
text_field_tag first_name
# => <label for=“obfuscated_first_name”> # <input name=“obfuscated_fist_name” id=“obfuscated_first_name” type=“text”>
By default it creates a text_field_tag and obfuscates the name of the field.
54 55 56 57 58 59 60 |
# File 'lib/mead_captcha/form_tag_helper.rb', line 54 def mead_obfuscate_tag(name, &block) if block_given? capture(mead_obfuscate_field(name), &block) else mead_obfuscate_field(name) end end |