SO I'm using Solsapce's User for usersto edit their profile and have discovered something I'm not sure how to describe or fix.
I have a normal edit profile with a few fields, I have declared certain fields to be required, the syntax is identical to SAFE forms required="fielda|fieldb" etc.
When the form is submitted with all things filled in correctly, the ajax does its thing nicely, if one of the required fields is missing content, then I cannot get it to show anything meaningful.
$('.user-edit').ajaxForm({
target: '#confirmation',
dataType: 'json',
success: function(result) {
$("#confirmation").html("<div class='success'>" +result.content+"</div>");
$("#confirmation").hide();
$("#confirmation").fadeIn(500);
},
error: function(jqxhr) {
$("#confirmation").html("<div class='alert'>" +jqxhr.responseText+"</div>");
//$("#confirmation").html("<div class='alert'>" +jqxhr.error+"</div>"); //Gives strange Javascript error (see comment below)
$("#confirmation").hide();
$("#confirmation").fadeIn(500);
}
});
Here's the kicker, Firebug shows this is the error response
{"error":"<p>The following fields are required: <ul><li>Birthday<\/li><\/ul><\/p>"}
This is whats displayed on the page, it includes the "error" and brackets and everything!
<div class="alert">{"error":"<p>The following fields are required: </p><ul><li>Birthday<\/li><\/ul><\/p>"}</li></ul></div>
On a successful post, this is the Firebug response and as I'm targeting "result.message" it displays fine:
{"success":true,"heading":"Successful Submission!","message":"Your profile has been successfully updated","content":"Your profile has been successfully updated"}
I've tried all manner of variations to get this ajax error displaying only the error content and am now doubtful that it ever will. Of course I could be a huge dumbass and missed something :)