Question

I'm still learning my way around in CodeIgniter.

I'd like to create a login form in my codeigniter application based on Ion Auth library.

I have installed the library following the instruction and it works fine when navigating to auth/login, auth/create_user, auth/logout, etc...

However, I don't need a stand alone page for login, I'd like to embed the form in my homepage. When I use the sample provided login view in my homepage, I get the following errors:

  • Message: Undefined variable: message
  • Message: Undefined variable: identity
  • Message: Undefined variable: password

I realize that the above variables are not defined in my view, I just can't figure out where and how they should be defined and why is that they work fine in the provided sample that came with the library?

Was it helpful?

Solution

config/routes.php

$route['login/check'] = 'auth/my_front_end_login';

view

<?php echo form_open('login/check'); ?>

<fieldset>
    <legend>login Credentials<legend>

    <label for="identity">&lowast; Identity</label>
    <input type="text" name="identity" id="identity" value="<?php echo set_value('identity');?>" />
    <?php echo form_error('identity');?>

    <label for="password">&lowast; Password</label>
    <input type="password" name="password" id="password" value="<?php echo set_value('password');?>" />
    <?php echo form_error('password');?>

    <label for="message">&lowast; Message</label>
    <input type="text" name="message" id="message" value="<?php echo set_value('message');?>" />
    <?php echo form_error('message');?>
</fieldset>

<?php echo form_close();?>

controllers/auth

public function my_front_end_login(){
   if($this->form_validation->run('login_frontend')) // uses config/form_validation.php
   {
       //validation passed, now attempt login via ION_AUTH
       //open ION_Auth library file and see what the login method requests in its params. 
      if(ION_Auth::login($params)) // Im not familiar with it
      {
         //login success
      }
      else
      {
         //login failure
      }
   }
   else
   {
       $this->index();
   }
}

OTHER TIPS

Do you load proper libraries needed, in controller related to view where you want to embed login form, for example "form_validation" if you use form_input($message) for example, ... anyway you can avoid this by checking if $var is_set.

<?php echo form_open('login/check'); ?>

<fieldset>
    <legend>login Credentials<legend>

    <label for="identity">&lowast; Identity</label>
    <input type="text" name="identity" id="identity" value="<?php echo set_value('identity');?>" />
    <?php echo form_error('identity');?>

    <label for="password">&lowast; Password</label>
    <input type="password" name="password" id="password" value="<?php echo set_value('password');?>" />
    <?php echo form_error('password');?>

    <label for="message">&lowast; Message</label>
    <input type="text" name="message" id="message" value="<?php echo set_value('message');?>" />
    <?php echo form_error('message');?>
</fieldset>

<?php echo form_close();?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top