Submit main_login_form with AJAX

So I’m trying to submit the login form in the background using AJAX but am having little to no luck. Essentially what I’m trying to do is to log into my store from another part of my site running under my CMS.



When I write up the HTML for the form with the same elements and hit submit, everything works fine. With the return_url argument I even come back right to the page where I started as if I never left. You can immediately see that a cookie has been set and if you navigate to the store you are logged in with no issues.



Take that same exact code and bind the submit button to jquery and send it in the background using an AJAX POST method and you get a 404 on /store/index.php.



Any thoughts? Are there better ways to do this to begin with? Also are there any AJAX log in mods, maybe I can look at how they have done it.



Thanks,



Joe

You need to ensure that whatever backend method you are using setups up browswer impersonation correctly. Otherwise it will fail.

Better use ajax to drive your own PHP file that curls into the cart. Much less headache.

I want to add ajax on login form submission so that if the login credentials are wrong then the invalid credentials notice will appear on login popup only and not homepage.

Can anyone help me please?

Thank you!!

I want to add ajax on login form submission so that if the login credentials are wrong then the invalid credentials notice will appear on login popup only and not homepage.

Can anyone help me please?

Thank you!!

At first, add cm-ajax class to the authorization form

design/themes/THEME/templates/views/auth/login_form.tpl

Then correct the controller

app/controllers/common/auth.php

Do not forget to add area and ajax request condition. E.g.

if (AREA == 'C' && defined('AJAX_REQUEST')) {
    ....custom code here....
}

At first, add cm-ajax class to the authorization form

design/themes/THEME/templates/views/auth/login_form.tpl

Then correct the controller

app/controllers/common/auth.php

Do not forget to add area and ajax request condition. E.g.

if (AREA == 'C' && defined('AJAX_REQUEST')) {
    ....custom code here....
}

Can u please explain in brief what will be there in custom code part??

Can u please explain in brief what will be there in custom code part??

Just check if there is any error and output error message, when use exit php function to stop further redirects