Welcome Guest, Not a member yet? Register   Sign In
My form validation wont work
#1

hi, am new to codeigniter and am currently using it to develop a web app for a bus ticket system as a school project. Am currently facing a serious issue with my registration form using the form validation and i need help. Dont know what i did wrong but here is the code:

Controller: register.php
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Register extends CI_Controller {

            public function __construct()
       {
               parent::__construct();
               $this->load->model('model_user');
       
       }

    public function index()
    {
        $data['title'] ='Register';

        $this->load->view('templates/header', $data);
        // $this->load->view('templates/navigation');
        $this->load->view('frontend/view_register');
        $this->load->view('templates/footer');
    }

    public function register_user()
    {
        $this->load->library('form_validation');
        //$this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span>', '</div>');
         $data['title'] = 'Register';



        $this->form_validation->set_rules('firstname', 'First name', 'required|min_length[3]|max_length[15]');
        $this->form_validation->set_rules('lastname', 'Last name', 'required|min_length[3]|max_length[15]');
        $this->form_validation->set_rules('username', 'Username', 'required|min_length[6]|max_length[15]|is_unique[user.username]');
        $this->form_validation->set_rules('email', 'Email', 'required|min_length[6]|max_length[30]|valid_email|is_unique[user.email]');
        $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[20]|matches[password_conf]');
        $this->form_validation->set_rules('password_conf', 'Confirm Password', 'required|min_length[6]|max_length[20]');

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

            $this->load->view('templates/header', $data);
            // $this->load->view('templates/navigation');
            $this->load->view('frontend/view_register');
            $this->load->view('templates/footer');

        }
        else
        {
            
             $this->model_user->insert_user();

            $this->load->view('templates/header');
            //$this->load->view('templates/navigation');
            $this->load->view('frontend/view_register_success');
            $this->load->view('templates/footer');

        }
        
    }
}

the rest of the codes are attached to this post. Kindly go through and help me out
Reply
#2

It would help people to help you if you told us what went wrong, what did you expect and what did you get? Just 'it does not work' and your code does not really help anyone to help you. What error message did you get? What process were you expecting that did not happen?

Best wishes,

Paul.
Reply
#3

(04-10-2016, 09:13 AM)PaulD Wrote: It would help people to help you if you told us what went wrong, what did you expect and what did you get? Just 'it does not work' and your code does not really help anyone to help you. What error message did you get? What process were you expecting that did not happen?

Best wishes,

Paul.

Well, i have a view page named view_register_success which is supposed to load after a user has successfully submitted the form but that doesn't work. Also, instead of having that view_register_page displayed after the form submission i still get the registration form being displayed with an error saying "Username required" even though i typed a username. One funny thing i also noticed happened was that i used set_value() in the view_register file for my first name, last name, username and email but anytime i submit the page and it gives me back the form i see the value for username at last name. I checked the the view_register page for the set_value() and everything seems to be ohk. S.o thats about it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB