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 7896705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:57:50+00:00 2026-06-03T07:57:50+00:00

I have a basic ajax form on my site utilizing the Js helper, it

  • 0

I have a basic ajax form on my site utilizing the Js helper, it works fine but when there are validation errors the update callback duplicates the entire page inside of my success div.

Success div:

<div id="success"></div>

Submit button:

echo $this->Js->submit('Send', array(
    'before'=>$this->Js->get('#sending')->effect('fadeIn'),
    'success'=>$this->Js->get('#sending')->effect('fadeOut'),
    'update'=>'#success',
    'class'=>'btn btn-primary'
));

Javascript:

$(document).ready(function(){

    $('#postkey, #gender, #hair, #location, #message').blur(function(){
        $.post(
            '/Cake_ajax/Posts/validate_form',
            { field: $(this).attr('id'), value: $(this).val() }
            //handleNameValidation
        );
    });

});

Validate form function in my controller:

public function validate_form(){
    if($this->RequestHandler->isAjax()){
        $this->request->data['Post'][$this->request['data']['field']] = $this->request['data']['value'];
        $this->Post->set($this->request->data);
        if($this->Post->validates()){
            $this->autorender = FALSE; // don't render a view
            $this->set('error','');
        }else{
          $this->layout ="ajax";
            $this->autoRender = FALSE;
            $error = $this->validateErrors($this->Post);
            $this->set('error',$this->Post->validationErrors[$this->request['data']['field']][0]);  
        }
    }
}

I don’t know if this is enough information to go on, If I need to post more code, just let me know.

thanks.

  • 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-06-03T07:57:51+00:00Added an answer on June 3, 2026 at 7:57 am

    I just tested your application by using your zip file.

    What I observed is that this is not the whole page that is put inside your #success div, but only the content of the Posts/add.ctp view.
    So basically this means the RequestHandler does its job correctly, meaning the layout that is used is the ‘ajax’ layout.
    To get rid of anything else that the form, the add.ctp page should not contain anything else that the form. In your case Posts/add.ctp contains navigation links, and that’s why they get duplicated.

    That said, what the submit button does currently is getting the content of Posts/add.ctp view and insert it in your empty #success div. But you never remove the form that was already on the page.
    What you could do is updating the content of a div that contains your first form, or even the content of the whole Posts/add.ctp view.

    In your case, simply updating the #content instead of the #success div could maybe suit your needs:

    echo $this->Js->submit('Send', array(
      'before'=>$this->Js->get('#sending')->effect('fadeIn'),
      'success'=>$this->Js->get('#sending')->effect('fadeOut'),
      'update'=>'#content',
      'class'=>'btn btn-primary',
      'controller'=>'posts',
      'action'=>'add'
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built a basic form with ajax validation and page redirection with PHP and
I'm using a basic registration form with AJAX, but the form is not connecting
I have a pretty basic jQuery ajax thing happening, but I want to mix
I have a basic login form, which uses ajax to login users. If the
In this basic jQuery, AJAX, PHP form I want to display errors next to
I have the basic code to rewrite a subdomain to another page. But how
I am writing a basic wizard for my web site. It will have 4
I have a basic newsletter signup form with an email field and two buttons
Sorry if this is basic, but I have been dealing with figuring this out
I am using the jQuery validation plugin on my form. I set the basic

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.