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

The Archive Base Latest Questions

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

I have the controller below and I would like it do the following things:

  • 0

I have the controller below and I would like it do the following things:

  • Show an error if the username is taken -> currently just submits as
    normal even through the specific user is in the database.

  • Populate with data if there was an error -> currently populates with
    the imported data if correct

  • Keep active state of the selected drop down menu item

View:

<h1><?php echo $companyName; echo nbs(1);?> - <?php echo $pageTitle; ?></h1>



<?php
if($success == TRUE) {
echo '<section id = "validation">Page Updated</section>';   
}
?>
    <p>Error: <?php echo validation_errors();?></p>
    <div class="formContent">
        <form action="createUser" method="post">
            <fieldset class="control-group">
                <label for="userName">User Name:</label><input type="text" id="userName" name="userName"  value="<?php echo set_value('userName'); ?>" placeholder="User Name">
                <label for="userPassword">User Password:</label><input type="password" id="userPassword" name="userPassword" value="<?php echo set_value('userPassword'); ?>" placeholder="User Password">
                <label for="userFirstName">First Name:</label><input type="text" id="userFirstName" name="userFirstName" value="<?php echo set_value('userFirstName'); ?>" placeholder="First Name">
                <label for="userLastName">Last Name:</label><input type="text" id="userLastName" name="userLastName" placeholder="Last Name">
                <label for="userEmail">E-Mail:</label> <input type="text" id="userEmail" name="userEmail"  placeholder="Admin E-mail">
                <label for="userGroup"> User Group:</label>
                    <select name="userGroup" id="userGroup">
                        <option value="select">Please Select</option>
                        <option value="admin">Admin</option>
                        <option value="user">User</option>
                    </select>
                <label for="userActive"> User Active:</label>
                        <select name="userActive" id="userActive">
                            <option value="select">Please Select</option>
                            <option value="yes">Yes</option>
                            <option value="no">No</option>
                        </select>
                <div>
                    <button type="submit" class="btn-primary">Create</button>
                </div>
                </fieldset>
        </form>
    </div>

Controller:

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

class createUser extends CI_Controller {


    public function index()
    {
        //Form Validation prep making sure its all clean

        $this->form_validation->set_rules('userName', 'User Name', 'trim|required|is_unique[users.userName]|xss_clean');
        $this->form_validation->set_rules('userPassword', 'User Password', 'trim|required|xss_clean|sha1');
        $this->form_validation->set_rules('userFirstName', 'First Name', 'trim|required|xss_clean');
        $this->form_validation->set_rules('userLastName', 'Last Name', 'trim|required|xss_clean');
        $this->form_validation->set_rules('userEmail', 'E-Mail', 'trim|required|xss_clean');
        $this->form_validation->set_rules('userGroup', 'User Group', 'trim|required|xss_clean');
        $this->form_validation->set_rules('userActive', 'User Active', 'trim|required|xss_clean');

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

        if($this->form_validation->run() == 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');
            $group = $this->input->post('userGroup');
            $active = $this->input->post('userActive');

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

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

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

            }

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

/* End of file login.php */
/* Location: ./application/controllers/admin/createUser.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:40:21+00:00Added an answer on May 30, 2026 at 1:40 am

    If I were you, I would use a callback ( http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks )

            $this->form_validation->set_rules('userName', 'User Name', 'trim|required|xss_clean|callback__checkUsername');
    

    as for your select drop downs, use the set_value() function

                    <select name="userGroup" id="userGroup">
                        <option value="select"<?=(set_value('userGroup')=='select')?' selected="selected"':''?>>Please Select</option>
                        <option value="admin"<?=(set_value('userGroup')=='admin')?' selected="selected"':''?>>Admin</option>
                        <option value="user"<?=(set_value('userGroup')=='user')?' selected="selected"':''?>>User</option>
                    </select>
    

    Good luck

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

Sidebar

Related Questions

I have a controller action which I would like to call another controller action.
I have a controller and I would like to require Authorization for all actions
I have the below controller. I return the view if a error occurs but
I have a base controller class and I would like to pass a Message
I have a Controller with two Edit methods (see below). When I submit the
I have a controller that stores various info (Ie. FormID, QuestionAnswerList, etc). Currently I
I have several uitextfields within a view and I would like to disable the
So, I have a page that looks like the following: alt text http://img704.imageshack.us/img704/5973/croppercapture3.png This
My Case: I have original Page Control app from Apple. I would like to
I would like for one tab in a UITabBarController to have a fixed position

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.