[eluser]Unknown[/eluser]
Hi all, I'm starting off developing a cms, but there's a few questions i had:
1.i know from a view, you would just use set_value ( 'username' ) to output the value back out, but in the controller, do i use set_value as well?
2.how would you set an error message to show up without creating a callback that would inevitably run when you form_validation->run();? I see form validation as a 2 step validation: first validate without the db, then check against the db ( see code )
Code:
<?php
class Login extends Controller {
function index() {
$this->load->helper ( 'form' );
$this->load->library ( 'form_validation' );
$this->form_validation->set_rules ( 'username', 'Username', 'trim|required|xss_clean' );
$this->form_validation->set_rules ( 'password', 'Password', 'trim|required|xss_clean|md5' );
if ($this->form_validation->run () == FALSE) {
$this->load->view ( 'loginview.php' );
} else { //if the form is valid, then we'll check the database
$this->load->model ( 'cms_model' );
if ($this->cms_model->login ( set_value ( 'username' ), set_value ( 'password' ) )) {
$this->load->view ( 'loginsuccess.php' );
} else {
//$this->form_validation->set_message('username','password mismatch);
$this->load->view ( 'loginview.php' );
}
}
}
}
?>
Thanks in advance,