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 7519443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:54:11+00:00 2026-05-30T01:54:11+00:00

I have a general create function that submits a new user to the database

  • 0

I have a general create function that submits a new user to the database – this works fine. Where I am is stuck is the following.

  • I know that I need the user that is signing up to have clicked the link in the email before the account can login. How do I implement that into my if statement when I run the create function?

  • I am a bit confused as to how to set my errors if any thing is correct or wrong to do with the activation process I have currently set the messages using $this->form_validation->set_message();. Do I need to use set_flashdata();? and how will echo these into the view?

When I create a new user I have the userActive field set at 0 by default and also the default group is set to users

Controller:

   <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller {


    public function index()
    {
        $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
        $data['pageTitle'] = "Create User";
        $this->load->view('frontend/assets/header', $data);
        $this->load->view('frontend/users', $data);
        $this->load->view('frontend/assets/footer');
    }

    public function create(){   

        //If form validation fails load previous page with errors else do the job and insert data into db

        if($this->form_validation->run('createUser') == FALSE)
        {
            $data['success'] = "";
        }else{
            $username = $this->input->post('userName');
            $password = $this->input->post('userPassword');
            $firstname = $this->input->post('userFirstName');
            $lastname = $this->input->post('userLastName');
            $email = $this->input->post('userEmail');

            $passwordHash = $this->encrypt->sha1($password); // Lets encrypt the password why sha1?  MD5 is for tossers

            $activateCode = $this->_activateCode(10);

            // If the data is correct follow through with db insert

            if($this->users_model->createUser($username,$passwordHash,$firstname,$lastname,$email,$activateCode))
            {
                $data['success'] = TRUE;

                redirect('frontend/users/create','refresh');

            }

        }
        $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
        $data['pageTitle'] = "Create User";
        $this->load->view('frontend/assets/header', $data);
        $this->load->view('frontend/user_create', $data);
        $this->load->view('admin/assets/footer');

        echo get_class($this);
        var_dump(method_exists($this, '_activateCode'));
    }

    function _userRegEmail($activateCode,$email,$firstname,$lastname){
        $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
        $data['companyEmail'] = $this->core_model->companyDetails()->coreCompanyEmail;
        $data['companyContact'] = $this->core_model->companyDetails()->coreContactName;
        $data['firstName'] = $firstName;
        $data['lastName'] = $lastname;
        $data['email'] = $email;
        $data['activateCode'] = $activateCode;

        $this->email->from($this->core_model->companyDetails()->coreCompanyEmail, $this->core_model->companyDetails()->coreCompanyName);
        $this->email->to($email);
        $this->email->subject($this->core_model->companyDetails()->coreCompanyName, 'User Registration Confirmation');

        $messageContent= $this->load->view('email_templates/userReg','', TRUE);

        $this->email->message($messageContent);

        //$this->email->send();
    }

    function usersconfirm(){

        $activateCode = $this->uri->segment(3);

        if($activateCode == '')
        {
            $this->form_validation->set_message('userConfirmError', 'Sorry you did not have a correct Activation Code.');
        }
            $userConfirmed = $this->users_model->confirm_user($activateCode);

            if($userConfirmed){
                $this->form_validation->set_message('userConfirmed', 'Thanks your account is now active you may login!');
            }else{
                $this->form_validation->set_message('userRecord', 'I am sorry we do not have any details with that Activation Code');
            }
    }

     function _username_check($username)
    {
        if($this->users_model->username_taken($username))
        {
            $this->form_validation->set_message('username_check', 'Sorry the username %s is taken!');
            return FALSE;
        }else{
            return TRUE;
        }
    }

    function _email_check($email)
    {
        if($this->users_model->email_check($email))
        {
            $this->form_validation->set_message('email_check','Sorry there is already a user with this %s');
            return FALSE;
        }else{
            return TRUE;
        }

    }

   function _activateCode($length)
    {
        return random_string('alnum', $length);
    }

}

/* End of file users.php */
/* Location: ./application/controllers/users.php */
  • 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-05-30T01:54:12+00:00Added an answer on May 30, 2026 at 1:54 am

    You can determine if the user has clicked the activation link by checking the database for userActive in your if statement.

    You can use flash data, sure. You can retrieve flash data with:
    $this->session->flashdata('item'); to echo out to the view.

    See http://codeigniter.com/user_guide/libraries/sessions.html > flash data

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

Sidebar

Related Questions

I have a general question about the way that database indexing works, particularly in
I have a function like this public void GetTablesWithUpperCaseName() { SqlConnectionStringBuilder objConnectionString = new
I have a general OOP question. If I have the following classes in C#
I have a general question that is rather open-ended (i.e. depends on platform, application
I have a general Java method with the following method signature: private static ResultSet
To have a general-purpose documentation system that can extract inline documentation of multiple languages,
So my setup for my web application is that I have a general header
I'm new to flash in general and have been writing a program with two
I have this function (produces the fibonacci sequence): unfoldr (\(p1, p2) -> Just (p1+p2,
Hallo, I have following jquery code for calling ASP.NET MVC controller method that is

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.