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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:04:19+00:00 2026-06-17T20:04:19+00:00

Lets say I have a login form and it has fields username and password.

  • 0

Lets say I have a login form and it has fields username and password. Both of the fields are required to be filled in and when you submit the form it has two different lines for them.

Username field is required.
Password field is required.

What I want to do is to show only the username field errors and when they don’t have any errors with username field, it will show the password field errors.

How would this be done?

Also, I remember there is a way to show errors only regarding a field, what was the snippet for it?

  • 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-17T20:04:20+00:00Added an answer on June 17, 2026 at 8:04 pm

    I suggest using a custom callback function tied to just one input, that checks both inputs and conditionally sets the desired message.

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class YourController extends CI_Controller {
    
        public function save() 
        {
            //.... Your controller method called on submit
    
            $this->load->library('form_validation');
    
            // Build validation rules array
            $validation_rules = array(
                                    array(
                                        'field' => 'username',
                                        'label' => 'Username',
                                        'rules' => 'trim|xss_clean|callback_required_inputs'
                                        ),
                                    array(
                                        'field' => 'password',
                                        'label' => 'Password',
                                        'rules' => 'trim|xss_clean'
                                        )
                                    );
            $this->form_validation->set_rules($validation_rules);
            $valid = $this->form_validation->run();
    
            // Handle $valid success (true) or failure (false)
            if($valid)
            {
                //
            }
            else
            {
                //
            }
        }
    
    
        public function required_inputs()
        {
            if( ! $this->input->post('username'))
            {
                $this->form_validation->set_message('required_inputs', 'The Username field is required');
                return FALSE;
            }
            else if ($this->input->post('username') AND ! $this->input->post('password'))
            {
                $this->form_validation->set_message('required_inputs', 'The Password field is required');
                return FALSE;
            }
    
            return TRUE;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have at least two lua script files. test1.lua test2.lua both define
I have a simple login form, username and password. Basically, When a user is
Here's the scenario I have a page lets say login.aspx having a button called
My oracle database has a user (Lets say SWEET). Inside SWEET schema, i have
Lets say I have a Spring MVC form like this: <form:form action=${pageContext.servletContext.contextPath}/secure/main.htm commandName=secure/main> <form:input
So lets say I have some forms like this: Form A: <form name=formA> <input
Lets say we have a web based application where users login to their own
Lets say I have a column of user ID's storing past login successes. Now,
let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {
Lets say have this immutable record type: public class Record { public Record(int x,

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.