I've got a few simple front-end forms that users can use to update their profiles. I'm using the combo of the jQuery Validate and Form plugins to handle validation and submission.
I can successfully update profiles when the fields are technically correct, but can't figure out how to get feedback from the server if an error occurs after submission (aka invalid password, username already in use, etc).
Here's an example of my password update form:
<form action="" class="secondary-content" method="post" accept-charset="UTF-8" id="pwForm">
<h2>Update password</h2>
<fieldset>
<input type="hidden" name="redirect" value="/profile">
<input type="hidden" name="action" value="users/saveUser">
<input type="hidden" name="userId" value="{{ user.id }}">
<input type="hidden" name="password" value="{{ currentUser.password }}">
<div id="passwordFields">
<div class="field">
<label for="npw">New password <a href="#npw" class="js-show-pw micro pull-right">Show password</a></label>
<input type="password" id="npw" name="newPassword" class="text-input" value="" required />
</div>
<div class="field">
<button class="button--red" type="submit">Update</button>
</div>
</div>
</fieldset>
</form>
Here is the javascript (in CoffeeScript syntax):
$('#pwForm').validate
submitHandler: (form) ->
$(form).ajaxSubmit
type: 'POST'
dataType: 'json'
beforeSubmit: ->
$(pwFields).transition opacity: 0
$('#pwLoader').spin(opts).transition opacity: 1
error: (xhr, status, error) ->
$('#pwLoader').stop().transition opacity: 0
$(pwFields).transition opacity: 1
$(pwFields).append('<label class="error">There was an error. Please try again.</label>')
success: ->
$('#pwLoader').stop().transition opacity: 0
$(pwFields).text ''
$(pwFields).html('<h3>Password updated</h3>').transition
opacity: 1
delay: 200
In this case, I'm actually tripping the "There was an error…" error no matter what I put in the field. If I pull out the javascript, the page refreshes and I don't get errors, but the password doesn't update.
I'm guessing it has to do with posting to the correct URL. Any ideas? Is it even worth using both/either of these plugins?
Thanks!