I'm throwing this up in hope that someone might spot a mistake because I've gone over this way to many times now. It was working fine for about ten minutes but then just broke.
I have a codeigniter website with a very simple contact form with 3 fields. I'm using isHappy.js to validate the form and then send off to the server. isHappy.js should stop the AJAX function until the form has validated but this parts not happening. If I click the submit button without filling out the form the validation errors flash up but then the ajax call is made and the form is submit.
Heres the Javascript:
$(function() {
$('#contact-form').isHappy({
fields: {
'#email': {
required: true,
message: 'How can I reach you sans email??'
},
'#subject': {
required: true,
message: 'Can you give me a clue to what you inquiring about please'
},
'#body': {
required: true,
message: 'More details please....'
}
}
});
$('#contact-form').bind('submit', function(e) {
e.preventDefault();
var query_params = $('#contact-form').serialize();
$.ajax({
type: 'POST',
url: 'http://website.dev:8080/contact/email/ajax',
data: query_params,
dataType: 'json',
success: function(string){
$('#contact-form').fadeOut('medium', function() {
$('#linkedin').after("<div style=\"clear:both;\" /><div id=\"contact-complete\" stlye=\"width:100%;height:200px;\"><h1>"+string+"</h1></div>").fadeIn('medium');
});
}
});
});
});
And the HTML:
<form action="http://website.dev:8080/contact/email" method="post" accept-charset="utf-8" id="contact-form">
<div class="contact-input">
<input type="text" name="email" id="email" placeholder="Your email" value="" />
</div>
<div class="contact-input">
<input type="text" name="subject" id="subject" placeholder="Subject" value="" />
</div>
<div class="contact-textarea">
<textarea rows="10" placeholder="How can I help you?" name="body" id="body"></textarea>
</div>
<input type="submit" value="Send" id="contact-click" />