1

i have the following modifuserviews, i have set the disabled input to hold id value,

<?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(); 
  ?>

then, here is the user/updateuser controller

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');
    }

when i open the form, it went great, then i try to submit the form without filling anything (just the ID automatically inputed),

then, the id disabled input changes into normal textbox like the following pictureenter image description here

how can i make the disabled still disabled after form_validation ? make the value still in the disabled input ? as you can see in the picture, the value which is 5 change into disabled and you can type here

update :

the following code not work

<input name="id" type="text" class="form-control" id="id" placeholder="Input id" value=<?php echo $id;?> disabled>
amphetamachine
  • 27,620
  • 12
  • 60
  • 72
Cignitor
  • 891
  • 3
  • 16
  • 36

1 Answers1

0

You have a typo, there are quotes missing for the value:

<input name="id" type="text" class="form-control" id="id" placeholder="Input id" value="<?php echo $id;?>" disabled>
Joerg
  • 3,102
  • 2
  • 24
  • 30