Sha256: 12ee0b48b5b3dc689905b0b5dbc2b485a1cac518e2f36662a13213f5bef26500

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # Exhibit feedback form
  class ContactForm
    include ActiveModel::Model

    attr_accessor :current_exhibit, :name, :email, Spotlight::Engine.config.spambot_honeypot_email_field, :message, :current_url, :request

    validates :email, format: { with: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i }

    # the spambot_honeypot_email_field field is intended to be hidden visually from the user,
    # in hope that a spam bot filling out the form will enter a value, whereas a human with a
    # browser wouldn't, allowing us to differentiate and reject likely spam messages.
    # the field must be present, since we expect real users to just submit the form as-is w/o
    # hacking what fields are present.
    validates Spotlight::Engine.config.spambot_honeypot_email_field, length: { is: 0 }

    def headers
      {
        to: to,
        subject: "#{I18n.t(:'blacklight.application_name')} Contact Form",
        from: %("#{name}" <#{email}>),
        cc: current_exhibit.contact_emails.join(', ')
      }
    end

    private

    def to
      Spotlight::Engine.config.default_contact_email || current_exhibit.contact_emails.first.to_s
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
blacklight-spotlight-2.13.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.12.1 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.12.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.11.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.10.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.9.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.8.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.7.2 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.7.1 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.7.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.6.1.1 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.6.1 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.6.0 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.5.2 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.5.1 app/models/spotlight/contact_form.rb
blacklight-spotlight-2.5.0 app/models/spotlight/contact_form.rb