Welcome Guest, Not a member yet? Register   Sign In
URI segment disappears after validation_run()
#4

My Controller (Login.php)
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Login extends CI_Controller {

    public function 
signin($course_id=null)
    {
        
$this->load->library('form_validation');
        
$this->form_validation->set_rules('username','Username','trim|required');
        
$this->form_validation->set_rules('password','Password','trim|required');
        if (!
$this->form_validation->run()) {
            
// validaiton failed
            
$this->load->view('view_signin');
        }
        else {
            
// validation success
            
if (!empty($course_id)) {
                
// redirect to enroll to course route
                
echo "go enroll this course, where course_tbl.course_id = '$course_id'";
            }
            else
            {
                
// redirect to normal site
                
echo "normal login, redirect to student/index";
            }
        }
    }


View (view_signin.php)
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Signin</title>
</head>
<body>
    <form action="http://localhost/codeigniter/index.php/login/signin" method="POST">
        <div>
            <label>username : </label>
            <input type="text" name="username" value="<?php echo set_value('username',null); ?>">
            <?php echo form_error('username'); ?>
        </div>
        <div>
            <label>password : </label>
            <input type="password" name="password" value="<?php echo set_value('password',null); ?>">
            <?php echo form_error('password'); ?>
        </div>
        <div>
            <button type="submit">submit</button>
        </div>
    </form>
</body>
</html>


Attached Files
.php   view_signin.php (Size: 698 bytes / Downloads: 20)
.php   Login.php (Size: 770 bytes / Downloads: 28)
Reply


Messages In This Thread
RE: URI segment disappears after validation_run() - by mk_seven - 09-29-2018, 02:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB