Reynaldi Rey
Reynaldi Rey

Reputation: 9

How to link to another page when clicking button

login.php (controller)

class login extends CI_Controller {
   public function index()
   {
     $this->load->view('login');
   }

   public function Click()
   {
      $action = $this->input->post('register'); // $_POST['start']; also works.
      if($action)
      {
          $this->load->view('register');
      }
   }
}

login.php(views)

<form action="" class="loginForm" method="POST">
    <div class="input-group">
        <input type="submit" id="submit" class="form-control" value="Login" name="login">
        <input type="submit" id="submit" class="form-control" value="Buat Akun" name="register" >
    </div>
</form>

how can I change my view to register.php after clicking register button. The error is I keep back to login page after clicking register.

Upvotes: 0

Views: 2014

Answers (3)

Anna
Anna

Reputation: 1

You can try this : In Login Controller:

class Login extends CI_Controller {

public function index()
{
    if($this->input->post('login') == 'Login'){
        $this->load->view('login');
    }else{
        $this->register();
    }
}

public function register(){
    $this->load->view('register');
}

}

In View :

Upvotes: 0

Anna
Anna

Reputation: 1

You need to enable mod_rewrite module in apache

Please follow below mention step to enable mod_rewrite module:

1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.

2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.You can do this easily by searching the keyword “mod_rewrite” from find menu.

3) Remove the “#” at the starting of the line, “#” represents that line is commented.

4) Now restart the apache server.

5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.

Upvotes: 0

Pradeep
Pradeep

Reputation: 9717

You can try this :

In Login controller :

      public function register()
      {
          $this->load->view('register');
      }

In view:

<form action="" class="loginForm" method="POST">
 <div class="input-group">
   <input type="submit" id="submit" class="form-control" value="Login" name="login">
   <a href="<?php echo base_url('login/register');?>" id="submit" class="form-control"  name="register" >Register</a>
 </div>
</form>

Upvotes: 2

Related Questions