Somehow, a simple form I have to sign up for a mailing list (which adds an email to a Google Apps Group, using gdatav2rubyclientlib) seems to fail occasionally. The form is submitted via POST through jQuery, and the Sinatra app (running on nginx/Passenger) handles the POST and emails me a confirmation. Occasionally, I get emails that "undefined" signed up. Somehow, the value the user types in is getting lost, but I'm not sure how or why. . .
Here's the HAML form from which the POST originates:
%li.sidebar-section
%span#mailing-list-slug
get on our mailing list
<br/>
%form{:id => "mailing_list_signup", :method => "post", :action => "/mailinglist/signup/the.grapevine"}
%input{:type => 'text', :name => 'email', :value => "enter your email…", :id => 'mailing-list-signup'}
%input{:id => "mailing_list_signup_button", :type => 'submit', :value => 'sign up'}
#thanks
thanks! you're in!
Here's the Javascript that makes the POST: $('#mailing_list_signup_button').click(function () { var email_address = $('input#mailing-list-signup').val();
$.ajax({
type: "POST",
url: "/mailinglist/signup/the.grapevine",
data: "email=" + email_address,
success: function() {
$('#thanks').show('slow');
}
});
var email_address = $('input#email').val();
$.post("/mailinglist/signup/the.grapevine",
$('form#mailing_list_signup').serialize(), function(result){alert(email_address);});
return false; });
});
Here's my route handler for the POST request
post '/mailinglist/signup/:list' do
adminuser = "ADMINUSERNAME"
password = "PASSWORD"
email = params[:email]
mailing_list = params[:list]
myapps = ProvisioningApi.new(adminuser,password)
myapps.add_member_to_group(email, mailing_list)
gmail(:to => 'MYEMAIL', :subject => "HEY HEY GUESS WHAT, #{params[:email]} JUST SIGNED UP FOR #{params[:list]}!", :body => "Totally not joking--")
end
Any thoughts would be appreciated!