aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/contact_validator.rb
blob: 0bc5628354691ee4634ce334256c3fc3ff186140 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# == Schema Information
# Schema version: 95
#
# Table name: contact_validators
#
#  name    :string
#  email   :string
#  subject :text
#  message :text
#

# models/contact_validator.rb:
# Validates contact form submissions.
#
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: contact_validator.rb,v 1.32 2009-09-17 21:10:05 francis Exp $

class ContactValidator < ActiveRecord::BaseWithoutTable
    strip_attributes!

    column :name, :string
    column :email, :string
    column :subject, :text
    column :message, :text

    validates_presence_of :name, :message => N_("Please enter your name")
    validates_presence_of :email, :message => N_("Please enter your email address")
    validates_presence_of :subject, :message => N_("Please enter a subject")
    validates_presence_of :message, :message => N_("Please enter the message you want to send")

    def validate
        errors.add(:email, _("Email doesn't look like a valid address")) unless MySociety::Validate.is_valid_email(self.email)
    end

end