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

  • Home
  • SEARCH
  • 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 8657841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:37:16+00:00 2026-06-12T15:37:16+00:00

I am having some problem in my login form like this I want to

  • 0

I am having some problem in my login form like this

enter image description here

I want to display an individually error beside of each field

here is the controller

function index()
{      
        $this->form_validation->set_rules('username','Username','trim|required|exact_length[4]|xss_clean');
        $this->form_validation->set_rules('password','Password','trim|required|min_length[4]|max_length[40]|xss_clean|callback_login');
        $this->form_validation->set_rules('jabatan','Jabatan','trim|required|xss_clean');

        if($this->form_validation->run() == false)
        {
            $this->load->view('login');
        }
        else
        {
            $this->load->view('welcome_message');
        }

}

function login()
{
    $username = $this->input->post('username');
    $password = $this->input->post('password');
    $jabatan = $this->input->post('jabatan');

    $value = $this->m_login->login($username,$password,$jabatan);

    if($value)
    {
        return true;
    }
    else
    {
        $this->form_validation->set_message('login', 'password salah');
        //delete redirect() and showing blank white screen
        return false;

    }

I made the <?php echo form_error(); ?> beside each field

<?php echo form_open('c_login/login'); ?>
            <table>
                <tr>
                    <td>Username</td>
                    <td><?php $inusername=array('name' => 'username', 'class' => 'GUI'); echo form_input($inusername); ?></td>
                    <td class="error"><?php echo form_error('username'); ?></td>
                </tr>

                <tr>
                    <td>Password</td>
                    <td><?php $inpassword=array('name' => 'password', 'class' => 'GUI', 'type' =>'password'); echo form_input($inpassword); ?></td>
                    <td class="error"><?php echo form_error('password'); echo $this->session->flashdata('login'); ?></td>
                </tr>

                <tr>
                    <td>Jabatan</td>
                    <td><?php $injabatan=array('keuangan' => 'keuangan', 'admin' => 'admin', 'hd' => 'head divisi', 'direktur' => 'direktur'); echo form_dropdown('jabatan',$injabatan,'keuangan','class = "gui"'); ?></td>
                    <td class="error"><?php echo form_error('jabatan'); ?></td>
                </tr>

                 <tr>
                    <td></td>
                    <td><?php $insubmit=array('name' =>'login','class' =>'button','value' => 'Login'); echo form_submit($insubmit); echo nbs(); $inreset=array('name' =>'reset','class' =>'button','value' => 'Hapus'); echo form_reset($inreset); ?></td>
                    <td class="error"><?php echo form_error(); ?></td>
                </tr>
            </table>
            <?php echo form_close(); ?>

How come the form_error() function is not echoing anything when I click login with the username and password field left blank?

  • 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-12T15:37:17+00:00Added an answer on June 12, 2026 at 3:37 pm

    you know problem in your validation you’re checking validation in index method of your class not in login method of your class and in your form you have given action to ci_login/login method which is redirecting if login is failed and its clearing form validation validate your fields on login method also and put all error message in session and display, i have made some changes in script have look here on this link Code modified

    for this changes you have to use url helper

    function index()
    {
        $this->form_validation->set_rules('username','Username','trim|required|exact_length[4]|xss_clean');
        $this->form_validation->set_rules('password','Password','trim|required|min_length[4]|max_length[40]|xss_clean|callback_login');
        $this->form_validation->set_rules('jabatan','Jabatan','trim|required|xss_clean');
    
        if($this->form_validation->run() == false)
        {
            $this->load->view('login');
        }
        else
        {
            //to check if the validation run correctly
            //$this->load->view('welcome_message');
    
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            $jabatan = $this->input->post('jabatan');
    
            $value = $this->m_login->login($username,$password,$jabatan);
    
            if($value)
            {
                redirect('welcome_message');
                //return true;
            }
            else
            {
                $this->form_validation->set_message('login', 'password salah');
                redirect('c_login',$login); //i want to pass $login into login form, then print
                return false;               //them as a form_error
    
            }
        }
    
    }
    
    
    <?php echo form_open(uri_string()); ?>
    <table>
        <tr>
            <td>Username</td>
            <td><?php $inusername=array('name' => 'username', 'class' => 'GUI'); echo form_input($inusername); ?></td>
            <td class="error"><?php echo form_error('username'); ?></td>
        </tr>
    
        <tr>
            <td>Password</td>
            <td><?php $inpassword=array('name' => 'password', 'class' => 'GUI', 'type' =>'password'); echo form_input($inpassword); ?></td>
            <td class="error"><?php echo form_error('password'); echo $this->session->flashdata('login'); ?></td>
        </tr>
    
        <tr>
            <td>Jabatan</td>
            <td><?php $injabatan=array('keuangan' => 'keuangan', 'admin' => 'admin', 'hd' => 'head divisi', 'direktur' => 'direktur'); echo form_dropdown('jabatan',$injabatan,'keuangan','class = "gui"'); ?></td>
            <td class="error"><?php echo form_error('jabatan'); ?></td>
        </tr>
    
         <tr>
            <td></td>
            <td><?php $insubmit=array('name' =>'login','class' =>'button','value' => 'Login'); echo form_submit($insubmit); echo nbs(); $inreset=array('name' =>'reset','class' =>'button','value' => 'Hapus'); echo form_reset($inreset); ?></td>
            <td class="error"><?php echo form_error(); ?></td>
        </tr>
    </table>
    <?php echo form_close(); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This little fiddle shows the problem I'm having. The login form on the right
I'm having some trouble with implementing CSRF protection on a login form. Here is
I'm having some problem with this statement declare @result int select @result = (select
I am having some problem with jsonp and jquery. This is my code -
I'm having some problem consuming REST Service and want to figure out what I'm
I'm building a website and having some problem. if the HTML code is like:
I am working on a windows form project and having some problem with UserControl
I'm having some problem with validations for multiple fields, specifically with case-sensitive unique validations
The following code is having some problem with the jQuery. <script type="text/javascript"> $(window).load(function() {
i am having some problem with position: absolute div. IE7 displays it next to

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.