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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:39:53+00:00 2026-06-17T13:39:53+00:00

I have built a Login form under PHP Codeigniter framework and its validation rules

  • 0

I have built a Login form under PHP Codeigniter framework and its validation rules are set.
The rules are working fine, but what I want to achieve is something different.

The login form has Username & Password Textbox set under a container called control-group.
Those who uses Bootstrap framework for HTML, knows this very well.

So the textbox code is like this :

<div class="control-group">
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" value="" placeholder="Username" class="login username-field" />
    <?php echo form_error('username','<span class="help-inline error">', '</span>'); ?>
</div>

You can see I have also placed span wrappers to error, so that it can be displayed in red color style. But what other thing I want to do is, I want to apply the error class to the control-group.

So that it become from

<div class="control-group">

To

<div class="control-group error">

I have already tried this by taking $error_class variable and passing it from Controller like this.

$data['error_class'] = '';
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');

if ($this->form_validation->run() == FALSE){
    $data['error_class'] = 'error';
    $this->load->view('administrator/login_view', $data);
}

But what it does is, it applied the error class to the control-group all the time. Even without submitting the form.

Any idea how to achieve this ?

Thanks in advance.

  • 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-17T13:39:55+00:00Added an answer on June 17, 2026 at 1:39 pm

    You have to run the validation only when the user is submitting the form.

    try doing this

    if($this->input->post())
    {
     //your form validation
    }
    

    This will only run when user submits a post request.

    EDIT:

    In addition to populate error on each individual field, use form_error('field_name') to check for error in each individual fields and echo the error class

    eg.

    <?=(form_error('field_name')?'error':'')?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application built with jQuery Mobile and PHP (CodeIgniter framework). Now
I have successfully built a login form using ajax and want to add a
I have built a site which requires user to login. Now I have decided
I built a Login application in which I have 3 Windows Log In Windows
I have a web-based system built with user login data based on session variables.
I have built a local DVD Database using Codeigniter, With film names etc in.
I want to have a login form on a charity website I am building
I have been working on a shop that is built in Python on the
I have a Dropdown in my TopBar, built with the Twitter Bootstrap CSS framework.
I have created a custom PHP script which uploads information submitted by a form

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.