Created
December 14, 2009 16:17
-
-
Save ivanacostarubio/256162 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app.rb | |
require 'rubygems' | |
require 'sinatra' | |
require 'yaml' | |
require 'wufoo' | |
config = YAML::load(File.read('config/wufoo')) | |
get '/neswletter' do | |
haml :neswletter | |
end | |
post '/thanks' do | |
client = Wufoo::Client.new('http://euforia.wufoo.com', config['api_key']) | |
submission = Wufoo::Submission.new(client, 'newsletter') | |
response = submission.add_params({ | |
'1' => params[:name], | |
'3' => params[:email] | |
}).process | |
if response.success? | |
#@mensaje = response.message | |
@mensaje = "Thanks for signing up to our newsletter." | |
else | |
# Something was wrong with the request | |
# (missing api key, invalid form, etc) | |
if response.fail? | |
@mensaje = response.error | |
end | |
# validation errors | |
unless response.valid? | |
errors = response.errors.collect { |e| "#{e.field_id} (#{e.code}): #{e.message}" } | |
@mensaje = errors * "\n" | |
end | |
end | |
haml :thanks | |
end | |
# newsletter.haml | |
%form{:action=>"/thanks", :method => "post", :id => "newsletter_form"} | |
%p | |
%label Name: | |
%input{ :type => "text", :name => "name", :class => "required"} | |
%p | |
%label Email: | |
%input{ :type => "text", :name => "email", :class => "required email" } | |
%center | |
%input{:class=>"submit", :type=>"submit", :value=>"Submit"} | |
# thanks.haml | |
%h1= @mensaje |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment