Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:58:04+00:00 2026-06-14T16:58:04+00:00

I am using the form validation functionality — it currently doesn’t allow a user

  • 0

I am using the form validation functionality — it currently doesn’t allow a user to enter incorrect username and password parameters when creating an account. But it’s meant to bounce the user back to the signup screen. Instead they’re brought through to the home screen, and if I use a username that’s been used before it goes into the database anyway.

Signup controller:

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', 'Username', 'required|min_length[5]|max_length[12]|trim');
        $this->form_validation->set_rules('password', 'Password', 'required|md5|trim');
        $this->form_validation->set_rules('username', 'Username', 'callback_usernameTaken');


        $username = $this->input->post('username');
        $password = $this->input->post('password');


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

        $this->membership->newUser($username, $password);
        $this->session->set_userdata('status', 'OK');
        $this->session->set_userdata('username', $username);
        redirect('home');
        }


        if ($this->membership->usernameTaken($username)) {
        $this->load->view('shared/header');
        $this->load->view('account/signuptitle');
        $this->load->view('account/signupview');
        $this->load->view('shared/footer');
        } else {
        $this->load->view('shared/header');
        $this->load->view('account/signuptitle');
        $this->load->view('account/signupview');
        $this->load->view('shared/footer');
        }
    }

}

I think the if ($this->membership->usernameTaken($username)) statement needs to arranged a certain way could it possibly be an else if statement?

Membership Model:

class Membership extends CI_Model {

    function Membership() {
        parent::__construct();
    }

    function newUser($username, $password) {
        $newMember = array('username' => $username,
        'password' => $password);
        $insert = $this->db->insert('membership', $newMember);
    }

    function usernameTaken($username) {
        $this->db->select('*')->from('membership')->where('username', $username);
        $query = $this->db->get();
        if ($query->num_rows > 0) {
        return true;
        } else {

        return false;
        }
    }

Thanks for the help again folks — I’ve been looking at similar issues on this site but I just found them too confusing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:58:05+00:00Added an answer on June 14, 2026 at 4:58 pm

    I believe when the register function runs, only this part of the code is executed before redirection.

    if ($this->form_validation->run()) {
    
        $this->membership->newUser($username, $password);
        $this->session->set_userdata('status', 'OK');
        $this->session->set_userdata('username', $username);
        redirect('home');
        }
    

    try doing something like this.

    if ($this->form_validation->run() && !$this->membership->usernameTaken($username)) {

        $this->membership->newUser($username, $password);
        $this->session->set_userdata('status', 'OK');
        $this->session->set_userdata('username', $username);
        redirect('home');
        }
    

    this way it wont redirect and proceed to execute lines below it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a registration form using validation inside the User model such as validates_confirmation_of
I am currently using $.blur(fn();) for form validation, but this only takes effect when
I am using jquery form validation to alert the user if the form is
I am using zend form validation for a phone number. and I want, user
I want to implement a functionality of changing user's password. It's basically a form
I'm creating a contact form using ExpressionEngine, however the built in contact form doesn't
I have made a form validation using ajax post method. But i got the
Client side form validation becomes easiest by using jQuery. I tried all validators and
I am using jquery validation plugin for form validation. I have added a custom
I'm using Springs annotations based form validation (mainly @NotBlank and @Length) which works great.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.