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

  • Home
  • SEARCH
  • 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 7419629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:06:15+00:00 2026-05-29T08:06:15+00:00

no title that fits this bug but this how it goes, i have form

  • 0

no title that fits this bug but this how it goes, i have form with a submit button when pressed jquery ajax calls the controller and the form validation is done if it fails the form is redrawn if it passes the page is redirected to the home page with flash message successes and thats where the bug happens it redraws the whole page in the content(header header footer footer). i hope it makes sense seeing is believing so here is the code

side notes: “autform” is a lib for creating forms “rest” is a lib for templates.

the jquery code:

$("form.user_form").live("submit",function() {
  $("#loader").removeClass('hidden');
  $.ajax({
      async :false,
      type: $(this).attr('method'),
      url: $(this).attr('action'),
      cache: false,
      data: $(this).serialize(),
      success: function(data) {
                $("#center").html(data);
                     $('div#notification').hide().slideDown('slow').delay(20000).slideUp('slow');
                }
  })

  return false;
 }); 

the controller

 function forgot_password()
{
        $this->form_validation->set_rules('login',lang('email_or_login'), 'trim|required|xss_clean');
        $this->autoform->add(array('name'=>'login', 'type'=>'text', 'label'=> lang('email_or_login')));
        $data['errors'] = array();
        if ($this->form_validation->run($this)) {                               // validation ok
            if (!is_null($data = $this->auth->forgot_password(
                    $this->form_validation->set_value('login')))) {
                    $this-> _show_message(lang('auth_message_new_password_sent'));
            } else {
                $data['message']=$this-> _message(lang('error_found'), false);  // fail
                $errors = $this->auth->get_error_message();
                foreach ($errors as $k => $v){
                     $this->autoform->set_error($k, lang($v));
                }
            }
        }
        $this->autoform->add(array('name'=>'forgot_button', 'type'=>'submit','value' =>lang('new_password')));
        $data['form']=  $this->autoform->generate('','class="user_form"');
        $this->set_page('forms/default', $data);
        if ( !$this->input->is_ajax_request()) { $this->rest->setPage(''); }
        else { echo  $this->rest->setPage_ajax('content');       }
    }
}

function _show_message($message, $state = true)
{
    if($state)
    {
        $data = '<div id="notification" class="success"><strong>'.$message.'</strong></div>';
    }else{
        $data = '<div id="notification" class="bug"><strong>'.$message.'</strong></div>';
    }
    $this->session->set_flashdata('note', $data);
    redirect(base_url(),'refresh');
}

i think it as if the redirect call is caught by ajax and instead of sending me the home page it loads the home page in the place of the form.

thanks for any help
regards

  • 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-29T08:06:16+00:00Added an answer on May 29, 2026 at 8:06 am

    OK found the problem and solution, it seemed you cant call a redirect in the middle of an Ajax call that is trying to return a chunk of HTML to a div, the result will be placing the redirected HTML in the div.

    The solution as suggested by PhilTem at http://codeigniter.com/forums/viewthread/210403/
    is when you want to redirect and the call is made by Ajax then return a value with the redirect URI back to Ajax and let it redirect instead.

    For anyone interested in the code:

    The Jquery Ajax code:

    $("form.user_form").live("submit", function(event) {
      event.preventDefault();
      $("#loader").removeClass('hidden');
      $.ajax({
          type: $(this).attr('method'),
          url: $(this).attr('action'),
          cache: false,
          dataType:"html",
          data: $(this).serialize(),
          success: function(data) {
              var res = $(data).filter('span.redirect');
              if ($(res).html() != null) {
                  [removed].href=$(res).html();
                  return false;
              }
              $("#center").html(data);
          },
          error: function() {
    
          }
      })
      return false;
    });  
    

    The PHP Controller

    function _show_message($message, $state = true, $redirect = '')
    {
        if ($state)
        {
            $data = '<div id="notification" class="success"><strong>'.$message.'</strong></div>';
        } else {
            $data = '<div id="notification" class="bug"><strong>'.$message.'</strong></div>';
        }
    
        $this->session->set_flashdata('note', $data);
    
        if ( !$this->input->is_ajax_request())
        {
            redirect(base_url() . $redirect, 'location', 302);
        }
        else
        {
             echo '<span class="redirect">'.base_url().$redirect.'</span>';
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text title that reads This User The Title Of The Post
I have this: <div class=one> <h2>Title that can be quite long and I don't
The title is a bit complicated, but it fits my problem. I have a
I have in a sidebar: <div id=yyy> [shortcode]</div> It outputs a title that when
That title may need some work. Perhaps after reading this, you may be able
OK, that title is a little unclear, but I can't think of a better
There is a question here in stackoverflow with the same title but that is
(I realize that my title is poor. If after reading the question you have
Sorry if the title is not that specific, but I don't know how else
I have a title that can have one or more lines. How can I

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.