how to visit or go to another page using button in codeigniter

Good day sir/maam!,

please help me to understand more about how MVC works. i am new in codeigniter and i cant really understand how the controller works when using a button. please teach me about how to navigate using button.. pls need your attention here.. :)

i have sample code here (login)

in my HTML

<?php echo validation_errors() ?>
    <?php echo form_open(current_url()) ?>
    <fieldset>
        <div class="pull-right">
            <label class="input login-input">
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-user"></i></span>
                        <input placeholder = "Email Address" class = "form-control" value = "<?php echo set_value('txt_email') ?>" name = "txt_email" type="email"></input>
                </div>
            </label>
            <label class="input login-input">
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-lock"></i></span>
                        <input placeholder = "Password" class = "form-control" name = "txt_password" type="password"></input>
                </div>
            </label>
            <div class = "button-inline">
                <button type="submit" class="login-button btn">Log in</button>
            </div>
            <hr class = "form group">

                <label> You do not have an accout yet? Please click <a>here</a> to register</label>
            <br>
                <h6>Note: This website is for personal user only..</h6>
        </div>
    </fieldset>
    <?php echo form_close() ?>

in my Controller

  public function login()
{
    $rules = array(
        array('field' => 'txt_email',
            'label' => 'Email',
            'rules' => 'required|valid_email|callback_check_login|trim',
             ),
        array('field' => 'txt_password',
            'label' => 'Password',
            'rules' => 'required|trim', 
            )
        );
    $this->form_validation->set_message('callback_check_login', 'invalid Email or Password');
    if ($this->is_validated($rules)){

         $this->render_client('homepage');
    }
    else{
    $this->render_login('login', $this->data);
    }
}
public function check_login(){
    $where = array(
        'email' => $this->input->post('txt_email'),
        'password' => $this->input->post('txt_password') 
        );
    return($this->database_model->select('tb_user', $where)) ? true : false;
}

and when i clicked the button(login), this url show

-> "http://localhost/myfirstwebsite/auth/login?txt_email=sample%40gmail.com&txt_password=sample123"

please i need your assistance! thanks!

Upvotes: 0

Views: 1477

Answers (1)

Darko
Darko

Reputation: 396

If i understand you correct you want to call your method "login" when you press your login button. In your view replace:

<?php echo form_open(current_url()) ?> 

with

<?php echo form_open('your_controller_name/login') ?>

In your confing.php you should set up your base_url:

$config['base_url'] = 'http://localhost/myfirstwebsite';

If you don't use mod_rewrite in your config.php your index_page shoud be set:

$config['index_page'] = 'index.php';

So when you click login button your form will point to your base URL plus the "your_controller_name/login" URI segments, something like this:

http://localhost/myfirstwebsite/index.php/your_controller_name/login

Upvotes: 1

Related Questions