Welcome Guest, Not a member yet? Register   Sign In
Optimizing login form
#1

[eluser]Unknown[/eluser]
I am learning CI, and I have a doubt, i want to optimizate the code in the login, because i have a lot of pages, where if you are not logged, the login form will appear.

The example of the tutorial:

Controller:
Code:
<?php

class Form extends CI_Controller {

function index()
{
  $this->load->helper(array('form', 'url'));

  $this->load->library('form_validation');

  $this->form_validation->set_rules('username', 'Username', 'required');
  $this->form_validation->set_rules('password', 'Password', 'required');
  $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required');

  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('myform');
  }
  else
  {
   $this->load->view('formsuccess');
  }
}
}
?>


View:

Code:
<html>
<head>
<title>My Form</title>
</head>
<body>

<?php echo validation_errors(); ?>

<?php echo form_open('form'); ?>

<h5>Username</h5>
&lt;input type="text" name="username" value="" size="50" /&gt;

<h5>Password</h5>
&lt;input type="text" name="password" value="" size="50" /&gt;

<h5>Password Confirm</h5>
&lt;input type="text" name="passconf" value="" size="50" /&gt;

<h5>Email Address</h5>
&lt;input type="text" name="email" value="" size="50" /&gt;

<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

This work fine, but i want to optimizate this for multiple page's with a option of login, the tipical .php View:

Code:
&lt;?php
     $sid = session_id();
     if($sid) {?&gt;
      <div class="blabla">
       &lt;!-- HTML --&gt;
      </div>&lt;?php
     }
     else {?&gt;
    
      
      
      <div id="login">
       <h3 class="hr_divider">Member Login</h3>
       &lt;?php
        echo validation_errors();
       ?&gt;
       &lt;?php
        echo form_open('form');
       ?&gt;
      
        <label for="username">Username:</label> &lt;input type="text" name="username" value="" size="50" /&gt;
        <label for="email">Password:</label> &lt;input type="text" name="password" value="" size="50" /&gt;
        <div class="cleaner_h10"></div>
        &lt;input type="submit" value="Submit" /&gt;
       &lt;/form&gt;
      </div>&lt;?php
     }
    ?&gt;

I search in forum, and understand the MVC model, i can't call Controllers from controllers or views (or is not right). The option is a library or helper, but i dont know how i can do it. I wanna save the name of variables, and dont put in all controllers this:

Code:
$this->form_validation->set_rules('username', 'Username', 'required');
  $this->form_validation->set_rules('password', 'Password', 'required');

Thanks!!

PD: Sorry the english Sad


Messages In This Thread
Optimizing login form - by El Forum - 06-11-2013, 10:30 PM
Optimizing login form - by El Forum - 06-12-2013, 01:40 AM
Optimizing login form - by El Forum - 06-12-2013, 10:15 PM
Optimizing login form - by El Forum - 06-13-2013, 12:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB