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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:15:44+00:00 2026-05-29T11:15:44+00:00

I have a form that is not outputting any error messages have I missed

  • 0

I have a form that is not outputting any error messages have I missed something?

Model:

function createUser($username = NULL ,$passwordHash = NULL ,$firstname = NULL ,$lastname = NULL ,$email = NULL,$group = NULL ,$active = NULL)
    {
        $data = array('userName' => $username, 'userFirstName' => $firstname, 'userLastName' => $lastname, 'userEmail' => $email, 'userPassword' => sha1($passwordHash), 'userGroup' => $group, 'userActive' => $active);

        $this->db->insert('users',$data);

        return TRUE;
    }

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: <input type="text" name="userName"  value="<?php echo set_value('userName'); ?>" placeholder="User Name"></label>
                <label for="userPassword">User Password: <input type="password" name="userPassword" value="<?php echo set_value('userPassword'); ?>" placeholder="User Password"></label>
                <label for="userFirstName">First Name: <input type="text" name="userFirstName" value="<?php echo set_value('userFirstName'); ?>" placeholder="First Name"></label>
                <label for="userLastName">Last Name: <input type="text" name="userLastName" value="<?php echo set_value('userLastName'); ?>" placeholder="Last Name"></label>
                <label for="userEmail">E-Mail: <input type="text" name="userEmail" value="<?php echo set_value('userEmail'); ?>" placeholder="Admin E-mail"></label>
                <label for="userGroup"> User Group:
                    <select name="userGroup" value="<?php echo set_value('userGroup'); ?>">
                        <option value="select">Please Select</option>
                        <option value="admin">Admin Group</option>
                        <option value="user">User Group</option>
                    </select>
                </label>
                <label for="userActive"> User Active:
                        <select name="userActive" value="<?php echo set_value('userActive'); ?>">
                            <option value="select">Please Select</option>
                            <option value="yes">Yes</option>
                            <option value="no">No</option>
                        </select>
                </label>
                <button type="submit" class="btn-primary">Create</button>
                </fieldset>
        </form>
    </div>

Controller:

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

        if($this->input->post('submit'))
        {
                $this->form_validation->set_rules('userName', 'User Name', 'trim|required|xss_clean|callback_username_check');
                $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 ($this->form_validation->run() == FALSE) {

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

            $username = $this->input->post('userName',TRUE);
            $password = $this->input->post('userPassword', TRUE);
            $firstname = $this->input->post('userFirstName', TRUE);
            $lastname = $this->input->post('userLastName',TRUE);
            $email = $this->input->post('userEmail',TRUE);
            $group = $this->input->post('userGroup',TRUE);
            $active = $this->input->post('userActive', TRUE);

            $this->db->escape($username);
            $this->db->escape($password);
            $this->db->escape($firstname);
            $this->db->escape($lastname);
            $this->db->escape($email);
            $this->db->escape($group);
            $this->db->escape($active);

            $passwordHash = $this->encrypt->sha1($password);

            if ($this->core_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');
            }else{
                $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');
            }
        }   
        }
    }

        function __username_check($userName){
        {
            if ($userName == $user->$userName) {

                $this->form_validation->set_message('username_check','Sorry the chosen username %s is taken!');

                return false;
            }else{
                return true;
            }

        }

    }

}

/* 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-29T11:15:45+00:00Added an answer on May 29, 2026 at 11:15 am

    You need to place the <input>s outside the <label> </label> tags! This is the main issue.

    Also:

    1. there’s no input named “submit”: your submit button, in fact, has no name attribute. And, btw, since you’re already using form_validation class, that check (if input->post('submit')) is redundant;
    2. Another redundant thing I see is passing TRUE (i.e., having it xss_cleaned) to the input->post method: you already have plenty of xss_clean validation rules, so why passing it again in that expensive extra processing, when already passed through it during validation check?
    3. Sidenote, if you’re using Active Record, or query bindings, you don’t have to escape variables, so I’d remove that part too 🙂
    4. And I believe your call to __username_check() will fail: the function, as for what concern the “callback_” validation rule, is “username_check”; and besides the double underscore is usually used for “magic methods” in PHP; you can safely remove both, or if you really want an underscore on the function name (just one) you might want to call “callback__check_username“.
    5. And you’re loading the same views three times, why? I believe you can rewrite the whole index method like this:

      function index()
      {
        $this->form_validation->set_rules('userName', 'User Name', 'trim|required|xss_clean|callback_username_check');
          $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 ($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);
      
              if ($this->core_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');
      }
      

    UPDATE:

    as for the username check, since v.2.0 of CodeIgniter you have that ability featured among the validation rules: if you place the is_unique rule, in fact, it will automatically query the database to check for that. The syntax is:

    is_unique[table.field]
    

    In your case, might be

     $this->form_validation->set_rules('userName', 'User Name', 'trim|required|is_unique[users.userName]|xss_clean');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a form that is not being read by serialize() function. <script type=text/javascript> function
I have a form with a field that does not live permanently on the
Fact: I'm not that good with jQuery. Problem: I have a form containing dynamically
I have a .xslt that translates xml from one form to another (I'm not
I have a form that will not open in the designer. I used the
I have a form that does not seem to want to write its data
I have a form that should not be submitted until the user has ticked
I have an invoice model, that has many invoice items. I have a form
I have client-side validations on a form that are outputting as label tags. They
I have this simple insert into query that seems to be outputting an error

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.