class Formular::Element::Form

Public Instance Methods

extra_hidden_tags() click to toggle source
# File lib/formular/elements.rb, line 66
def extra_hidden_tags
  token_tag + utf8_enforcer_tag + method_tag
end

Private Instance Methods

method_tag() click to toggle source

because this mutates attributes, we have to call this before rendering the start_tag

# File lib/formular/elements.rb, line 90
def method_tag
  method = options[:method]

  case method
  when /^get$/ # must be case-insensitive, but can't use downcase as might be nil
    options[:method] = 'get'
    ''
  when /^post$/, '', nil
    options[:method] = 'post'
    ''
  else
    options[:method] = 'post'
    Hidden.(value: method, name: '_method').to_s
  end
end
token_tag() click to toggle source
# File lib/formular/elements.rb, line 72
def token_tag
  return '' unless options[:csrf_token].is_a? String

  name = options[:csrf_token_name] || '_csrf_token'

  Hidden.(value: options[:csrf_token], name: name).to_s
end
utf8_enforcer_tag() click to toggle source
# File lib/formular/elements.rb, line 80
def utf8_enforcer_tag
  return '' unless options[:enforce_utf8]

  # Use raw HTML to ensure the value is written as an HTML entity; it
  # needs to be the right character regardless of which encoding the
  # browser infers.
  %(<input name="utf8" type="hidden" value="✓"/>)
end