Cannot get my form to submit using the Foundation 5 Abide code. If it take out the validation the code/ajax form submits perfectly. See code below, I'm sure I'm missing something. The form is only checking for valid email addresses right now, though I will add in checking for the first name and last name fields later if I can get this one validation to work first.
Form:
<form method="post" name="adduser" id="adduser" data-abide="ajax">
<fieldset>
<legend>Add New User</legend>
<div class="small-2 columns">
<label class="inline">First Name
<input type="text" name="fname"/>
</label>
</div>
<div class="small-2 columns">
<label class="inline">Last Name
<input type="text" name="lname"/>
</label>
</div>
<div class="small-4 columns">
<label class="inline">Email
<input type="email" name="email"/>
</label>
</div>
<div class="small-2 columns">
<label class="inline">Access Type
<select name="accesslvl">
<option value="1" selected>User</option>
<option value="2">Admin</option>
</select>
</label>
</div>
<div class="small-2 columns">
<input type="submit" class="button small adduserbtn" value="Add User" />
</div>
</fieldset>
</form>
Script:
$('#adduser').on('valid.fndtn.abide', function() {
$.ajax({
type: 'post',
url: 'addnewuser.php',
data: $('form').serialize(),
success: function () {
alert('User has been added successfully');
window.location.reload(true);
}
});
});
Previous to adding the validation into the equation, I was submitting the form via this script, which was working fine and still does work when I remove the data-abide settings from the form.
$('form').on('submit', function (a) {
a.preventDefault();
$.ajax({
type: 'post',
url: 'addnewuser.php',
data: $('form').serialize(),
success: function () {
alert('User has been added successfully');
window.location.reload(true);
}
});
});
});