Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6390993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:03+00:00 2026-05-25T03:37:03+00:00

I use the Auth component. I have an Ajax login form and I want

  • 0

I use the Auth component. I have an Ajax login form and I want to show a success/failure message under the form without a page refresh.

But when I submit a form (using jquery.form.js):

$('#loginform').ajaxForm(function(data) {
    alert(data);
});

it returns home.ctp contents in the alert in case of success and returns the login form’s HTML codes in case of failure!

I want to receive $this->Auth->loginError in alert(data).

These are some app_controller beforeFilter settings:

function beforeFilter(){
   $this->Auth->loginRedirect = false;
   $this->Auth->logoutRedirect = false;
   $this->Auth->loginError = __('Invalid e-mail or password.', true);
   $this->Auth->autoRedirect = false;
   $this->autoRender = false;
   $this->render('login','ajax');
}

I used loginRedirect to render some logics and making a JSON object for the jQuery process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:37:03+00:00Added an answer on May 25, 2026 at 3:37 am

    You can use the solution from blogpost CakePHP Form Validation with Ajax Using jQuery.

    Basically, the thing is, to distinguish a standard from an Ajax request via:

    if ($this->RequestHandler->isAjax()) { /*If it is an Ajax call*/ }
    else { /* If it is a standard action request */ }
    

    and still need to turn the debug level to 0 (Configure::write('debug',0)) and use Ajax layout to not output data in standard XHTML layout in /app/views/layouts/default.ctp.

    Debug of submitted form looks like this:

    Configure::write('debug', 0);
        $this->layout = 'ajax';
        if ($this->RequestHandler->isAjax()) {
            if (!empty($this->data)) {
                $this->Post->create();
                $this->Post->set($this->data['Post']);
                if($this->Post->validates()) {
                    if ($this->Post->save($this->data)) {
                        $message = __('The Post has been saved.', true);
                        $data = $this->data;
                        $this->set('success', compact('message', 'data'));
                    }
                } else {
                    $message = __('The Post could not be saved. Please, try again.', true);
                    $Post = $this->Post->invalidFields();
                    $data = compact('Post');
                    $this->set('errors', compact('message', 'data'));
                }
            }
        }
    

    And the output after it is made in JSON format:

    // Error output
    {"errors":{
        "message":"The Post could not be saved. Please, try again.",
        "data":{
            "Post":{
                "title":"This field cannot be left blank.",
                "body":"This field cannot be left blank."
            }
        }
    }}
    
    // Success output
    {"success":{
        "message":"The Post has been saved.",
        "data":{
            "Post":{
                "id":"",
                "title":"Lorem ipsum dolor sit amet",
                "body":"Lorem ipsum dolor sit amet, aliquet ...",
                "published":"1"
            }
        }
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Posts and a Users controller. I use the Auth Component and
I am using the auth component but I don't want to use a username
At the moment I use Auth Component for users to login / logout -
I have a CakePHP website with its own login system using the Auth component.
Possible Duplicate: How to use Basic Auth and Jquery and Ajax I want to
I am trying to use django-social-auth to implement google openid login into my app,
I have a rather simple CakePHP app that uses the Auth component to restrict
I have 2 authenticate method for Auth component. Default and Special . First method
i am trying to use gigya auth properties to login users on my website.
I am using cakephps Auth Component to login to my site. When I correctly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.