EllisLab text mark
Advanced Search
     
How to get form validation to work
Posted: 10 November 2012 11:20 AM   [ Ignore ]
Joined: 2012-11-04
22 posts

Im currently working on a register part of a website and i have a rule set that a username between 5 and 12 characters plus a password must be entered. If a users details are within these parameters they are then brought to the login screen. Yet if I enter a users details that are correctly entered i still get the incorrect parameters error - why is this?

<?php
class Signup extends CI_Controller
{
 
function Signup()
 
{
  parent
::__construct();
  
$this->load->model('membership');
 
}

 
function index()
 
{
  $this
->load->view('shared/header');
  
$this->load->view('account/signuptitle');
  
$this->load->view('account/signupview');
  
$this->load->view('shared/footer');
 

 
 
  
function register()
  
{
   
   $this
->load->helper(array('form''url'));
   
   
$this->load->library('form_validation');
   
   
   
$this->form_validation->set_rules('username''required|min_length[5]|max_length[12]');
   
$this->form_validation->set_rules('password''required');
  

   
$username $this->input->post('username');
   
$password $this->input->post('password');
   
   
   
    if( 
$this->form_validation->run() == FALSE
   
{
   
    $this
->load->view('shared/header');
    
$this->load->view('account/signuptitle');
    
$this->load->view('account/signupview');
    
$this->load->view('shared/footer');
   
   
}
  
   
 
  
else if ($this->membership->usernameTaken($username)){
    
     
echo "name taken!";
    
}
    
    
else if ( $this->form_validation->run() == TRUE{
    
     
echo "Name and password incorrect parameters!";
    
    
}
     
    
else if($this->membership->newUser($username$password))
    
{
    
     redirect
('login');
    
}
     

 
  }  
 

 
Posted: 10 November 2012 06:02 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts
else if ( $this->form_validation->run() == TRUE{
    
     
echo "Name and password incorrect parameters!"

if you pass validation, you send an error message.

Also, look at callbacks in the form_validation - your logic is a bit of a mess, and unnecessary

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?