dimanche 1 mars 2015

Form submits twice using Foundation Abide

I am running a script based on if Foundation's Abide function is valid on a certain form or not. When it is valid for some reason the form is submitting twice? Why?


I have two separate ajax calls for two separate fields because they both need to be checked for uniqueness. If they are both unique the form then needs to submit Everything works like it is supposed to however, the form gets submitted twice.


I have tried two versions of the .submit() where the first one didn't allow the form to submit at all: $("#ClientCreateForm").submit(); so I found a previous question and changed that to: $("#ClientCreateForm")[0].submit(); Which now it does submit just twice.


Here is my code:



$("#ClientCreateForm").on('valid.fndtn.abide', function (event) {

var number = $("input[name='number']").val();
var dataString = 'number='+number;
$.ajax({
type: "POST",
url: "/bamboo/panda/actions/check_number/",
data: dataString,
success: function(data) {
var data = data.trim();
if(data == '1')
{
var email = $("input[name='email']").val();
var EdataString = 'email='+email;
$.ajax({
type: "POST",
url: "/bamboo/panda/actions/check_email/",
data: EdataString,
success: function(Edata) {
var Edata = Edata.trim();
if(Edata == '1')
{
$("#ClientCreateForm")[0].submit();
}
else
{
$(".email-field").attr('class', 'number-field small-3 columns error');
$(".email-field .error").html('Must be a unique email');
return false;
}
}
});
}
else
{
$(".number-field").attr('class', 'number-field small-3 columns error');
$(".number-field .error").html('Must be a unique number');
return false;
}
}
});
event.preventDefault();


The code for submitting my form is in HTML and looks like this:



<fieldset>
<legend>Form Actions</legend>
<input type="submit" value="Create Client" name="MyClientSubmit" class="button small success pull-right">
</fieldset>

Aucun commentaire:

Enregistrer un commentaire