Welcome Guest, Not a member yet? Register   Sign In
How To Retrieve Form Validation errors?
#2

[eluser]pickupman[/eluser]
I don't think there is really any need for a die() in CI. What you might find helpful is to try and use json to respond to any ajax requests.
Code:
//application/config/constants.php
//Global define for AJAX Requests
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

//In your controller
if($this->form_validation->run() == FALSE)
{
  if(IS_AJAX){
    $data['response'] = 'failed';
    $data['message']  = validation_errors();
    echo json_encode($data);
  }else{
    $data['errors'] = validation_errors();
    $this->load->view('form', $data);
  }  
}else{
  //A successful routine here
  if(IS_AJAX){
    $data['response'] = 'true';
    $data['message']  = 'Success';
    echo json_encode($data);
  }else{
    $this->load->view('form_success', $data);
  }  
}

Now you will have a working form with the same code base that works with(out) js. Create some if statements handling the json response back.


Messages In This Thread
How To Retrieve Form Validation errors? - by El Forum - 07-02-2010, 06:16 PM
How To Retrieve Form Validation errors? - by El Forum - 07-02-2010, 09:28 PM
How To Retrieve Form Validation errors? - by El Forum - 08-22-2010, 06:08 PM
How To Retrieve Form Validation errors? - by El Forum - 08-22-2010, 06:29 PM
How To Retrieve Form Validation errors? - by El Forum - 08-22-2010, 07:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB