1

I have a login form saved as a snippet, which I include in the pages where it's needed, and the script that runs it is in the header include template. Basically, I use Ajax to avoid showing that interstitial page when logging in, and it works as expected for that. However, when I add error_handling="inline" and put error variables in the form template, nothing shows up -- the form clears itself, but no messages show up.

This is the form:

{exp:profile:login return="{path={segment_1}/{segment_2}/{segment_3}/{segment_4}}" include_jquery="no" json="yes" error_handling="inline"}
<label for="username">Username</label>
<input type="text" name="username" value=""  maxlength="32" class="input" size="25" />        {error:username}
<label for="password">Password</label>
<input type="password" name="password" value="" maxlength="32" class="input" size="25" />{error:password}
     {if auto_login} <br />
     <label for="auto_login">Remember Me? </label>
     <input type="checkbox" name="auto_login" value="1" checked="checked"> {/if}
<span id="logmein" class="btnGrey">Login</span>
  {/exp:profile:login}
 |{errors}{error}:{field}|{/errors} 

This is the jQuery, just in case that's the problem:

<script>
var login_options = { 
    success: do_login,  
    dataType: 'json',
    resetForm: true
};
    function do_login(data, statusText, xhr, $form)  {   
    if (data.success) {                                                   
        $("input[name=XID]").val(data.XID);
        window.location.replace("{path={segment_1}/{segment_2}/{segment_3}/{segment_4}}");   
    }  
    return true; 
};    
$(document).ready(function() { 
$("#logmein").click(function(){ 
  var form = $(this).closest("form"); 
   $(form).ajaxForm(login_options);
   $(form).submit(); 
}); 
...
</script>

I am running EE version 2.5.5 and Profile:Edit 1.0.7. I tried all the variations of error variables shown here, and nothing works.

1

If memory serves me correctly, the profile:login form already avoids EE's interstitial page, unlike the standard EE login form. So you may not need to do any of this at all.

But if that's not that case...submitting a form via ajax will override any error_handling chosen. So instead of getting inline errors, you get an object in the JSON response (data.errors) which contains all of the error messages. You should use an else condition where you've got if (data.success), loop through data.errors and append them to your form.

1
  • Aha! That's really all I needed to know, I didn't see anything about the error handling not working with ajax (and for the record I am pretty much convinced I did have it without ajax before and it was showing me the interstitial page -- but I could be wrong about that. I know it was doing that up until I got the ajax working.)
    – dotlizard
    Mar 1 '13 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.