I use the following code to display a login form in html view part
<form action="/TestApp/index.php/my_controller/validate" method="POST" method="GET">
Username: <input name="name" type="text"><br />
Password: <input name="word" type="password"><br />
<label name = "error"></label><br />
<input type="submit" value="Login">
</form>
inside controller I validate username and password. The following lines of code help me to get textbox values into controller.
$uName = $_POST['uname'];
$pWord = $_POST['pword'];
I need to assign/set string value to label error from controller.
How can I do that? please help me.
Controller
class My_controller extends CI_Controller {
public function login()
{
$this->load->view('login_view');
}
public function validate()
{
$this->load->model('login');
if((isset($_POST['name'])) && (isset($_POST['word'])) && !empty($_POST['name']) && !empty($_POST['word']))
{
$uName = $_POST['name'];
$pWord = $_POST['word'];
if($this->model_users->checkUser($uName) == 1) {
if($this->model_users->checkPassword($uName) == $pWord) {
echo 'Loggedin!';
$this->session->set_userdata('login_state', TRUE);
} else {
// Incorrect password;
redirect( '/' );
$error = "Incorrect password!";
}
} else {
// Username does not exist;
redirect( '/' );
$error = "Username does not exist!";
}
} else {
// Username or Password field is empty;
redirect( '/' );
$error = "Username or Password field is empty!";
}
}
}