• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI segment disappears after validation_run()

#1
im trying to go from mysite.com/signin/1 to mysite.com/course/enroll/1
but after validation_run() the segments just goes away.

PHP Code:
public function signin(course_id=null) {
 
 if(!$this->form_validation->run()){
 
   // wrong input
 
 }
 
 else{
 
   if(!empty($course_id)) {
 
      redirect(base_url('course/enroll/'.$course_id));
 
   }
 
   else {
 
      redirect(base_url('student'));
 
   }
 
 }


i kept on being redirected to mysite.com/student even tho course_id is not empty.

right now, i just used session to get around this problem but i know that is not an efficient solution.
Reply

#2
Have you done anything with routes? Based on the limited code shown you should not need to, but that's the only thing that comes to mind - assuming you have actually directed the browser mysite.com/signin/1 and not accidentally used mysite.com/signin/.
Reply

#3
(09-28-2018, 08:13 AM)dave friend Wrote: Have you done anything with routes? Based on the limited code shown you should not need to, but that's the only thing that comes to mind - assuming you have actually directed the browser mysite.com/signin/1 and not accidentally used mysite.com/signin/.

i have

my routes for these are
Code:
// normal signin
$route['signin'] = 'login/signin';

// if the student is not currently log in and wants to enroll to a course
// $1 is the course_id
$route['signin/(:num)'] = 'login/signin/$1';

normal signing-in works fine, but when i have to pass the course_id segment it disappears and redirects me to mysite.com/student
Reply

#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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.