如何在orderigniter中验证表单

I would like to validate my login form like Google does.

First check username then check password; If both are empty then there is only an error on the username box.

In CodeInginter, if both are empty it prints each field is required messages.

Can we mimic this functionality easily with CodeIgnightor?

you need to research before you post some question. These kind of information available in codeIgniter user guide. Any way i am providing simple example.

View file: login.php

   <form action="<?php echo ROOT_FOLDER ?>/controller_name/post_login" method="post" >
                    <p>
                        <label>Email:</label> <?php echo form_error('email'); ?><br />
                        <input type="text" class="text" name="email" value="<?php echo set_value('email'); ?>" />
                    </p>

                    <p>
                        <label>Password:</label> <?php echo form_error('passwd'); ?><br />
                        <input type="password" name="passwd" class="text" value="" />
                    </p>

                    <p>
                        <input type="submit"  class="submit" value="Login" />                               

                    </p>
    </form>

Controller function which is written in controller file..........

 public function post_login()
    {

        $error_in_validation=set_form_validation($this->config->item('login_form'));

        if($error_in_validation){
            show_form_validation_error('controller_file_name/login');
        }
        else
        {
            $email=$this->input->post('email');
            $passwd=$this->input->post('passwd');
            $ret=$this->model_file_name->user_login($email, $passwd);

            if($ret == NULL){

                $model=array();
                $model['error_msg']=$this->config->item('login_form_error_code_1');;
                $this->load->view('controller_file_name/login',$model);             
            } else {
                redirect("ro_manager/home");
            }

        }

    }

After this you need to create you need to create a file name called form_validation in config folder. In that you need to write the validation rules as per user guide.

     $config['login_form'] = array (
                        array 
                        (
                            'key' => 'email', 
                            'value' => 'Email',
                            'rule' => 'trim|required|valid_email|xss_clean'
                        ),
                        array
                        (
                            'key' => 'passwd', 
                            'value' => 'Password',
                            'rule' => 'trim|required|alpha_numeric|xss_clean'
                        )
                      );

Try like this way

   $this->form_validation->set_rules('email', 'Email', 'required');

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

    $this->load->view('myform');

   }else{
     $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
     if($this->form_validation->run() == FALSE){
       $this->load->view('myform');
     }
     $this->load->view('formsuccess');
   }