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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:55:36+00:00 2026-06-16T01:55:36+00:00

I’m using Codeigniter framework to create my web application. I have a login form

  • 0

I’m using Codeigniter framework to create my web application.

I have a login form for the users to input their username and password as well as a remember me checkbox. After the user submits the form it uses jQuery ajax to submit the form and send the post data to the login controller submit function for data checking and manipulation. After the submit function is ran a JSON array is returned if the user was logged in. If the user is successfully logged in he/she is sent to the dashboard and if they weren’t logged in successfully then an error message is displayed and under each of the user inputs displays the corresponding message to the rule that didn’t pass the CI form validation rules.

As of right now it displays a message saying it didn’t pass validation but I’m having an issue with figuring out how to display the validation rule that didn’t pass under the user input box.

<div style="display:none"  id="message_container"><button type="button" class="close" data-dismiss="alert">&times;</button></div>
    <div class="login_container">
<?php $attributes = array('id' => 'login_form', 'class' => 'form-horizontal'); ?>
<?php echo form_open('login/submit', $attributes); ?>
    <div class="form-row row-fluid">
        <div class="spa12">
            <div class="row-fluid">
                <?php $attributes = array('class' => 'form_label span12'); ?>
                <?php echo form_label('Username<span class="icon16 icomoon-icon-user-3 right gray marginR10"></span>', 'username', $attributes); ?>
                <?php $attributes = array('name' => 'username', 'id' => 'username', 'value' => '', 'class' => 'span12 text valid'); ?>
                <?php echo form_input($attributes); ?>
            </div>
        </div>
    </div>
    <div class="form-row row-fluid">
        <div class="span12">
            <div class="row-fluid">
                <?php $attributes = array('class' => 'form_label span12'); ?>
                <?php echo form_label('Password<span class="icon16 icomoon-icon-locked right gray marginR10"></span><span class="forgot"><a href="#">Forgot your password?</a></span>', 'password', $attributes); ?>
                <?php $attributes = array('name' => 'password', 'id' => 'password', 'value' => '', 'class' => 'span12 password'); ?>
                <?php echo form_password($attributes); ?>
            </div>
        </div>
    </div>
    <div class="form-row row-fluid">                       
        <div class="span12">
            <div class="row-fluid">
                <div class="form-actions">
                    <div class="span12 controls">
                        <input type="checkbox" id="keepLoged" value="Value" class="styled" name="logged" />Keep me logged in
                        <button type="submit" class="btn btn-info right" id="loginBtn">
                            <span class="icon16 icomoon-icon-enter white"></span>
                            Login
                        </button>
                    </div>
                </div>
            </div>
        </div> 
    </div>
</form>
</div>


public function submit()
{
    $output_status = 'Notice';
    $output_title = 'Not Processed';
    $output_message = 'The request was unprocessed!';

    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_check_username');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
    $this->form_validation->set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');

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

    }
    else
    {
        $output_status = 'Error';
        $output_title = 'Form Not Validated';
        $output_message = 'The form did not validate successfully!';
    }

    echo json_encode(array('output_status' => $output_status, 'output_title' => $output_title, 'output_message' => $output_message));
}

public function check_username($str)
{
    if (preg_match('#[0-9]#', $str) && preg_match('#[a-z]#', $str)) 
    {
        return TRUE;
    }
    $this->form_validation->set_message('check_username', 'This is not have an accepted value!');
    return FALSE;
}

EDIT:

“error_messages”:{“username”:”This is not have an accepted value!”}}

Since I’m submitting this form via jQuery ajax function I’m trying to figure out how I’m going to make my if statement. Take into consideration I’ll have multiple inputs that will have to be placed under each text field unless there’s a better idea.

  • 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-16T01:55:37+00:00Added an answer on June 16, 2026 at 1:55 am

    If all you are trying to do is append the string of error messages to your $output_message you might be able to do this:

    $output_message = 'The form did not validate successfully! Errors: ' . $this->form_validation->error_string();
    

    You can set custom error messages using:

    $this->form_validation->set_message('username', 'Invalid Username');
    

    Edit as per your comment, if you want to send back the error messages you should try something like this:

    echo json_encode(array('output_status' => $output_status, 'output_title' => $output_title, 'output_message' => $output_message, 'error_messages' => $this->form_validation->error_array()));
    

    And to display those error messages I would add placeholders in your html and append the message there

    CodeIgniters Form Validation Library Source:

    /**
     * Get Array of Error Messages
     *
     * Returns the error messages as an array
     *
     * @return  array
     */
    public function error_array()
    {
        return $this->_error_array;
    }
    

    So it seems this is a new addition coming in Version 3.0, so for now you could just extend the Form Validation Library by adding a file inside your application/libraries/ and name it MY_Form_validation.php and inside it place this:

    class MY_Form_validation extends CI_Form_validation {
        public function __construct()
        {
            parent::__construct();
        }
    
        /**
         * Get Array of Error Messages
         *
         * Returns the error messages as an array
         *
         * @return  array
         */
        public function error_array()
        {
            return $this->_error_array;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.