dongyan2469 2014-07-23 06:59
浏览 46
已采纳

如何将validation_errors()放在textfield的右侧?

I have followed the learning tutorials in CodeIgniter and Im currently creating a program using the same procedure on my reference(link posted below) where there is a log-in form. I have no problem with the functions, I just want to put the validation_errors() at the right side of the textfield where if the username is empty or incorrect, the error message will display on the right side of the textfield. Is there a way to do this? or should I use javascript instead of using this validation_errors()? Hope someone will help me. Thanks!

Here's the code in VIEW:

<h3>Log-In with CodeIgniter</h3>
<?php echo validation_errors(); ?>
<?php echo form_open('verifylogin'); ?>
<label for="username">Username:</label>
<input type="text" size="20" id="username" name="username"/>
<br/>
<label for="password">Password:</label>
<input type="password" size="20" id="password" name="password"/>
<br/>
<input type="submit" value="Log-In"/>
</form>

Here's the code in CONTROLLER:

    function index() {
    $this->load->library('form_validation');
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
    if($this->form_validation->run()==FALSE) {
        $this->load->view('login_view');
    }
    else {
        redirect('home', 'refresh');
    }
}

function check_database($password) {
    $username=$this->input->post('username');
    $result=$this->user->login($username, $password);
    if($result) {
        $sess_array=array();
        foreach($result as $row) {
            $sess_array=array('id'=>$row->id, 'username'=>$row->username);
            $this->session->set_userdata('logged_in', $sess_array); 
        }
        return TRUE;
    }
    else {
        $this->form_validation->set_message('check_database', 'Invalid username or password');
        return FALSE;
    }
}

Reference: http://www.codefactorycr.com/login-with-codeigniter-php.html

enter image description hereenter image description hereenter image description hereenter image description here

  • 写回答

3条回答 默认 最新

  • dqppv86022 2014-07-23 07:08
    关注
    <h3>Log-In with CodeIgniter</h3>
    
    
    
    <?php if (form_error('password')=="Invalid username or password")
     {
        echo form_error('password');
     }
    ?>
    
    <?php echo form_open('verifylogin'); ?>
    <label for="username">Username:</label>
    <input type="text" size="20" id="username" name="username"/><?php echo form_error('username'); ?>
    <br/>
    <label for="password">Password:</label>
    <input type="password" size="20" id="password" name="password"/><?php echo form_error('password'); ?>
    <br/>
    <input type="submit" value="Log-In"/>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题