Skip to content

Commit 0bfeec0

Browse files
configured email
1 parent ef213ae commit 0bfeec0

File tree

5 files changed

+118
-54
lines changed

5 files changed

+118
-54
lines changed

.idea/workspace.xml

+82-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/stylesheets/pages.css.scss

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ $nav-button-color: rgb(147, 179, 241);
2525

2626
body {
2727
font-family: Verdana;
28+
29+
input[type='text'], textarea {
30+
font-family: Verdana;
31+
font-size: 1em;
32+
}
33+
2834
background-image: url('cross_scratches.png');
2935
width: $page-width;
3036
@include center;
@@ -178,9 +184,12 @@ footer {
178184

179185
.contact {
180186

181-
label {
182-
183-
187+
.error {
188+
color: #EF2343;
189+
font-weight: bold;
190+
font-size: 1.5em;
191+
line-height: 20px;
192+
text-align: center;
184193
}
185194

186195
input {

app/controllers/pages_controller.rb

+21-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def nav_items
1616
end
1717

1818
def make_contact
19-
if @captcha.valid? && ContactMailer.contact_email(@captcha.values[:name], @captcha.values[:email], @captcha.values[:message]).deliver
19+
if @captcha.valid? && form_valid && send_message
2020
redirect_to :root
2121
else
22-
redirect_to :make_contact_pages
22+
redirect_to :contact_pages, :flash => { :error => @failure_reason }
2323
end
2424
end
2525

@@ -31,8 +31,26 @@ def setup_negative_captcha
3131
:spinner => request.remote_ip,
3232
:fields => [:name, :email, :message],
3333
:params => params)
34-
pie = 3
3534
end
3635

36+
def form_valid
37+
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
38+
39+
if @captcha.values[:name].blank? || @captcha.values[:email].blank? || @captcha.values[:message].blank?
40+
@failure_reason = "All fields are requried!"
41+
return false
42+
end
43+
44+
unless @captcha.values[:email] =~ email_regex
45+
@failure_reason = "Valid email addresses only!"
46+
return false
47+
end
48+
49+
return true
50+
end
51+
52+
def send_message
53+
return ContactMailer.contact_email(@captcha.values[:name], @captcha.values[:email], @captcha.values[:message]).deliver
54+
end
3755

3856
end

app/views/pages/contact.html.haml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Contact
33
= form_tag(:pages_make_contact, :class => 'contact') do
44
= raw negative_captcha(@captcha)
5+
%p.error
6+
= flash[:error]
57

68
.left-side
79
= negative_label_tag(@captcha, :name, 'Name:')

config/routes.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
get :home
77
get :about
88
get :contact
9+
post :make_contact
910
end
1011
end
1112

12-
post 'pages/make_contact'
13-
1413
# The priority is based upon order of creation:
1514
# first created -> highest priority.
1615

0 commit comments

Comments
 (0)