[eluser]joeizang[/eluser]
Hi y'all,
I have a quick question, and sorry I am a NOOB as I have been using codeigniter for about 2 months. I need to know is it ok to echo out validation_errors() from inside a controller? This is what I see in a lot of tutorials on line but from learning OOP in php it's srongly discouraged to echo directly from a class. I am trying to show validation errors on a form but doing anything else apart from echoing does not give me access to the errors. Here is my code:
<?php
//assuming the class and extending it etc is done right.
function create()
{
$this->form_validation->set_rules('articletitle','Article Title','required|xss_clean|trim');
$this->form_validation->set_rules('author','Article Author', 'required|xss_clean|trim');
$this->form_validation->set_rules('articlebody','Article\'s Body','required|xss_clean|trim');
if($this->form_validation->run() == FALSE)
{
//$this->addarticle();
return validation_errors();
}
else{
$data = array(
'articletitle' => $this->input->post('articletitle'),
'articleauthor' => $this->input->post('author'),
'articlebody' => $this->input->post('articlebody')
);
$this->load->model('articles');
$this->articles->createarticle($data);
// $this->load->view('editorfiles/successful');
}
}
?>
when I try to insert it works fine but when I have errors it does not show at all. I am ajaxing the entire process so there is not page refresh so I want the page to show up in the same div as where the form was. here is my ajax code:
//JQuery code
function submithandler(formname)
{
$(formname).submit(function(eve){
eve.preventDefault();
$.ajax({
url: 'create',
type: 'POST',
data: $('#manualform').serialize(),
beforeSend: function(){
$('#busy').show('slow');
},
success: function(data){
$('#busy').hide('slow');
processform(data);//handles the form processing
}
})
});
}
//end JQUERY code
any thots?!