Welcome Guest, Not a member yet? Register   Sign In
How to get form validation to work
#1

[eluser]James_B[/eluser]
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?

Code:
<?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');
    }
    


  }  


}
#2

[eluser]jmadsen[/eluser]
Code:
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




Theme © iAndrew 2016 - Forum software by © MyBB