0

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.

  • If your ip shows in url that means you must set the base url in config.php as it recommends it. https://stackoverflow.com/questions/45450302/how-to-set-base-url-in-codeigniter –  Mar 20 '18 at 12:11
  • If you are looking for a solution based on your html markup, I think you need to change button type to "button" and add onClick javascript event that uses window.location to redirect to register url. Right now submit type button is always posting to the form action url. – thephpx Mar 20 '18 at 15:12

3 Answers3

2

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>
Pradeep
  • 9,667
  • 13
  • 27
  • 34
  • This site can’t be reached ERR_CONNECTION_REFUSED – Reynaldi Rey Mar 20 '18 at 11:41
  • have u properly setup url and .htaccess – Pradeep Mar 20 '18 at 11:45
  • I don't setup that, so my url when I click register http://my-url/register. it's supposed be: http://localhost:8000/myurl-url/register – Reynaldi Rey Mar 20 '18 at 11:49
  • and when I try http://localhost:8000/my-url/register. it's redirect to XAMPP dashboard, I'am very confuse about that. – Reynaldi Rey Mar 20 '18 at 11:51
  • you have to properly set your config file and add .htaccess file in your project folder : pls read : https://www.codeigniter.com/user_guide/general/urls.html – Pradeep Mar 20 '18 at 11:53
  • I have add this too .htaccess but it still redirect to dashboard RewriteEngine On RewriteBase /my-url/ do you know what's my problem? – Reynaldi Rey Mar 20 '18 at 13:07
  • It may be the htaccess issue. To confirm that, try remove htaccess file and access url by adding index.php http://localhost:8000/projectfolder/index.php/remaining-url – Vibin TV Mar 20 '18 at 13:17
  • also if u are using htaccess then rewrite_module (mod_rewrite) need to be enabled in apache config – Vibin TV Mar 20 '18 at 13:21
  • Add this in .htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] – Pradeep Mar 20 '18 at 13:31
  • set $config['base_url'] = 'http://localhost/project_folder_name/'; $config['index_page'] = ''; – Pradeep Mar 20 '18 at 13:33
0

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()”.

Anna
  • 1
  • 3
0

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 :

Anna
  • 1
  • 3