Welcome Guest, Not a member yet? Register   Sign In
validation_form error
#1

[eluser]dilawaiz[/eluser]
hello everyone ! i'm a beginner of codeIgnitor and trying to make basic login page but im having error that verifylogin page doesnt exist although i have created it . plz anyone guide me where i'm mistaken . thank you


<?php
echo validation_errors();
?>
<?php
echo form_open ('verifylogin');
?>
<label for="username"> username:</label>
&lt;input type="text" size="20" id="username" name="username"/&gt;
<br/>
<label for= "password"> password:</label>
&lt;input type="password" size="20" id="password" name="password"/&gt;
<br/>
&lt;input type="submit" value="Login"/&gt;
&lt;/form&gt;

#2

[eluser]TWP Marketing[/eluser]
[quote author="dilawaiz" date="1348337306"]hello everyone ! i'm a beginner of codeIgnitor and trying to make basic login page but im having error that verifylogin page doesnt exist although i have created it . plz anyone guide me where i'm mistaken . thank you


&lt;?php
echo validation_errors();
?&gt;
&lt;?php
echo form_open ('verifylogin');
?&gt;
<label for="username"> username:</label>
&lt;input type="text" size="20" id="username" name="username"/&gt;
<br/>
<label for= "password"> password:</label>
&lt;input type="password" size="20" id="password" name="password"/&gt;
<br/>
&lt;input type="submit" value="Login"/&gt;
&lt;/form&gt;

[/quote]

First, enclose your code in the [ code]...[/ code] tags to make it easier to read
From the USER GUIDE: http://ellislab.com/codeigniter/user-gui...elper.html

The action method usually includes the controller and method to be called when the user submits the form.
Your code:
Code:
form_open ('verifylogin');
Doesn't appear to follow the expected format for the action variable and CI cannot find a controller named: 'verifylogin'
#3

[eluser]dilawaiz[/eluser]
thanks and do u mean that i should write form_open('home/verifylogin') rather than form_open('verifylogin') ?
#4

[eluser]TWP Marketing[/eluser]
[quote author="dilawaiz" date="1348384009"]thanks and do u mean that i should write form_open('home/verifylogin') rather than form_open('verifylogin') ? [/quote]

Yes, form_open('home/verifylogin') is the intended format to pass the action parameter using the form helper. Assuming that 'home' is your controller class name and 'verifylogin' is the method you want to run when the user clicks on the submit button.
It also assumes that you have set the correct value for 'base_url' in /application/config/config.php
#5

[eluser]dilawaiz[/eluser]
thanks for your reply ... but VerifyLogin is my controller class and index() is its function which i want to be run on user's click. so do i have to write form_open('VerifyLogin/index') ? i tried this but it didn't work . moreover, i haven't set any base_url . what it should be like ?
and also i want to ask that in form_open('...') we are supposed to write the page or the controller/funtion ? or both scenarios can be adopted ?

if you make me able to make this login page .. i would be really thank full to you .
#6

[eluser]dilawaiz[/eluser]
and also plz check my helper class .
Code:
function index(){
        $this->load->helper(array('form','url'));
        $this->load->view('login_view');
        
    }

and in autoload i have set like this
Code:
$autoload['helper'] = array('url');
#7

[eluser]TWP Marketing[/eluser]
[quote author="dilawaiz" date="1348485752"]and also plz check my helper class .
Code:
function index(){
        $this->load->helper(array('form','url'));
        $this->load->view('login_view');
        
    }

and in autoload i have set like this
Code:
$autoload['helper'] = array('url');
[/quote]

In reverse order:

2) You don't need to load the 'url' helper twice. If you load it in config/autoload.php, then you do not need to load it again in the controller.
If your form uses the action 'verifylogin', then you have a loop and no code to process the form data. It will just reload the same view: 'login_view'.

1) OK, Since your controller class name is Verifylogin and you intend to run the index function
Your action variable for form_open('verifylogin') is correct, but check the capitalization. The name in the class declaration IS capitalized, and the usage in form_open() may or may not be (sorry, it varies with the operating system). Try using uncapitalized and Capitalized.

Since I haven't seen your entire controller code, be sure you have the correct constructor code for your version of CI.

Also check the permissions on the controller file itself.
#8

[eluser]dilawaiz[/eluser]
thanks for replying but i'm sorry i'm still not able to resolve . here's my code
Code:
&lt;?php  if(! defined ('BASEPATH')) exit ('No direct script access allowed');

class Login extends CI_Controller{
    function __construct()
    {
        parent::__construct();
    }
    function index(){
        $this->load->helper(array('form','url'));
        $this->load->view('login_view');
        
    }
}
    
?&gt;
...... view class....
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;simple login with codeignitor&lt;/title&gt;

&lt;/head&gt;

&lt;body bgcolor="pink"&gt;
<h1>simple login with codeignitor</h1>
&lt;?php
    echo validation_errors();
?&gt;
&lt;?php
    echo form_open ('VerifyLogin');
?&gt;
    <label for="username"> username:</label>
     &lt;input type="text" size="20" id="username" name="username"/&gt;
     <br/>
     <label for= "password"> password:</label>
      &lt;input type="password" size="20" id="password" name="password"/&gt;
      <br/>
      &lt;input type="submit" value="Login"/&gt;
      &lt;/form&gt;
    
    
    

&lt;/body&gt;

&lt;/html&gt;
..... the problem controller class Sad ......
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class VerifyLogin extends CI_Controller {

/*function __construct()
{
   parent::__construct();
   $this->load->model('user','',TRUE);
}
       */
function index()
{
      $this->load->model('user','',TRUE);

   //This method will have the credentials validation
   $this->load->library('form_validation');

   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this->form_validation->run() == FALSE)
   {
        

     //Field validation failed.&nbsp; User redirected to login page
      validation_errors();
    
     $this->load->view('login_view');
   }
   else
   {
     //Go to private area
     redirect('home', 'refresh');
   }

}

function check_database($password)
{
   //Field validation succeeded.&nbsp; Validate against database
   $username = $this->input->post('username');

   //query the database
   $result = $this->user->login($username, $password);

   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' => $row->id,
         'username' => $row->username
       );
       $this->session->set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
}
}
?&gt;
#9

[eluser]TWP Marketing[/eluser]
[quote author="dilawaiz" date="1348483944"]
...
moreover, i haven't set any base_url . what it should be like ?
...
[/quote]

In your file: application/config/config.php
Set the base_url value as in the example
Code:
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = 'http://yourdomain.com/';
if you are using localhost, then you will need to use the URL which points at your site root directory.
If you leave it blank, then CI will try to "guess" at the base_url. It is not always successful.
#10

[eluser]dilawaiz[/eluser]
thanks alot... im through it Smile i was not properly calling the function form_open (...) and yeah also base_url thing.. now its working . thanks for your help !! Smile




Theme © iAndrew 2016 - Forum software by © MyBB