Codeigniter:禁用引导程序更改为验证后启用

时间:2015-02-22 13:45:24

标签: html twitter-bootstrap codeigniter

我有以下modifuser次观看,我已将已停用的输入设为保留id值,

<?php echo form_open('user/updateuser');
 ?>
<legend>Update User</legend> 

<div class="form-group">
    <label for="id">ID</label>
    <input name="id" type="disabled" class="form-control" id="id" placeholder="Input id" value=<?php echo $id;?> disabled>
     <?php echo form_error('id'); ?>     
  </div>

<div class="form-group">
    <label for="username">Username</label>
    <input name="username" type="input" class="form-control" id="id" placeholder="Input Username" value=<?php echo $username;?>>
     <?php echo form_error('username'); ?>   
  </div>

  <div class="form-group">
    <label for="password">Old Password:</label>
    <input name="old_password" type="password" class="form-control" id="password" placeholder="Input Old Password"" value =<?php set_value('old_password'); ?>>
    <?php echo form_error('old_password')?>
  </div>

  <div class="form-group">
    <label for="password">New Password:</label>
    <input name="password" type="password" class="form-control" id="password" placeholder="Input Password" ">
    <?php echo form_error('password')?>
  </div>


  <div class="form-group">
    <label for="password">New Password Confirmation:</label>
    <input name="password_conf" type="password" class="form-control" id="password" placeholder="Input Password Confirmation">
    <?php echo form_error('password_conf')?>
  </div>

  <div class="form-group">
        <label for="email">Email address</label>
        <input name="email" type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" value="<?php echo $email; ?>">
        <?php echo form_error('email')?>
  </div>      

  <div class="form-group" align="center">
    <button type="submit" class="btn btn-success">Submit</button> <button type="reset" class="btn btn-danger">Clear</button>
  </div>
  </div>
  </div>
  <?php 
    echo form_close(); 
  ?>

然后,这是user/updateuser控制器

function index()
{
    //This method will have the credentials validation    
    $this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert">', '</div>');
    $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
    $this->form_validation->set_rules('old_password', 'Old Password', 'trim|required|xss_clean|callback_check_password');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|matches[password_conf]');
    $this->form_validation->set_rules('password_conf', 'Password Confirmation', 'trim|required|xss_clean');
    $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean');

    if($this->isloggedin('logged_in'))
    {                           
        if($this->form_validation->run() == FALSE)
        {                       
            $data = array(
                'sess_username' =>  $this->isloggedin('logged_in'),
                'id'            =>  $this->input->post('id'),
                'username'      =>  $this->input->post('username'),
                'email'         =>  $this->input->post('email')

            );                                  

            $this->load->view('header');
            $this->load->view('main/menu_super_admin',$data);
            $this->load->view('user/modifuser');
            $this->load->view('footer');
        }
        else
        {           
            $query = $this->m_user->updateuser($this->input->post('id'),$this->input->post('username'),md5($this->input->post('password')),$this->input->post('email'));

            if($query)
            {
                echo "<script>window.onload = function() { return alert(\" Update User Success ! \"); }</script>";
            }
            else 
            {
                return false;
            }

        redirect('user/user', 'refresh');
    }
    }
    else
    {
        redirect('login', 'refresh');
    }

当我打开表单时,它变得很棒,然后我尝试提交表单而不填写任何内容(只是自动输入的ID),

然后,id禁用的输入会更改为普通文本框,如下图enter image description here

如何在form_validation后禁用仍然禁用?使值仍然在禁用输入中?如图所示,5的值变为disabledyou can type here

更新:

以下代码不起作用

<input name="id" type="text" class="form-control" id="id" placeholder="Input id" value=<?php echo $id;?> disabled>

1 个答案:

答案 0 :(得分:0)

您有输入错误,该值缺少引号:

<input name="id" type="text" class="form-control" id="id" placeholder="Input id" value="<?php echo $id;?>" disabled>