Skip to content

Instantly share code, notes, and snippets.

@lxcodes
Created June 23, 2011 01:23
Show Gist options
  • Save lxcodes/1041698 to your computer and use it in GitHub Desktop.
Save lxcodes/1041698 to your computer and use it in GitHub Desktop.
Ajax Post -- Registration
<form id="registration" action="/register" method="post" accept-charset="utf-8">
<table>
<tr>
<td><input type="text" name="first_name" value="" id="first_name" class="validate[required]"><br /><label for="first_name"><%= t[:forms][:firstName] %></label></td>
<td><input type="text" name="last_name" value="" id="last_name" class="validate[required]"><br /><label for="last_name"><%= t[:forms][:lastName] %></label></td>
</tr>
<tr>
<td><input type="text" name="company" value="" id="company" class="validate[required]"><br /><label for="company"><%= t[:forms][:company] %></label></td>
<td><input type="text" name="title" value="" id="title" class="validate[required]"><br /><label for="title"><%= t[:forms][:title] %></label></td>
</tr>
<tr>
<td><input type="text" name="city" value="" id="city" class="validate[required]"><br /><label for="city"><%= t[:forms][:city] %></label></td>
<td><input type="text" name="country" value="" id="country" class="validate[required]"><br /><label for="country"><%= t[:forms][:country] %></label></td>
</tr>
<tr>
<td><input type="text" name="mobile_number" value="" id="mobile_number" class="validate[required,custom[email]]"><br /><label for="mobile_number"><%= t[:forms][:mobile] %> #</label></td>
</tr>
</table>
<p id="attending"><%= t[:forms][:attending] %>:
<label style="text-transform:uppercase"><strong><%= t[:random][:yesh] %></strong><input type="radio" name="attending" value="true" class="validate[required]"></label>
<label style="text-transform:uppercase"><strong><%= t[:random][:nein] %></strong><input type="radio" name="attending" value="false" class="validate[required]"></label>
</p>
<p class="floatRight"><input type="submit" id="submit" class="submit" value="<%= t[:forms][:submit] %>"><span><img src="/images/ajax-loader.gif" alt="Ajax Loader" class="ajaxLoader"></span></p>
</form>
$(document).ready(function(){
$('#submit').click(function(e){
e.preventDefault();
$('.submit').attr("disabled", "true");
var al = $('ajaxLoader').show();
var $(data) = $('#registration').serialize();
$.post("/register", $(data) , function(json){
if(json && json.success)
$.modal("<div><p>Obrigada por fazer a sua inscrição, a LORD tem certeza de estar disponibilizando um ótimo conteúdo para você. Você já votou no assunto que gostaria de ver e ouvir nesse evento? Se não, aproveite e faça isso agora mesmo!</p></div>");
}).complete(function(){
al.hide();
}).error(function(res){
json = $.parseJSON(res.responseText);
$.modal("<div><h1>Error</h1><br><p>There was an error!<br>Error Message: "+json.error+"</p></div>");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment