2014-05-24 45 views
-3

我的視圖頁password.php如何使用jQuery改變笨密碼和驗證領域

<form> 
    oldpassword<input type="password" name="oldpassword" id="oldpassword"/><br> 

    newpassword<input type="password" name="newpassword" id="newpassword"/><br> 

    confirmpassword<input type="password" name="confirmpassword" id="confirmpassword"/><br> 

    <input type="submit" name="submit" value="changepassword"/> 
</form> 

應放在控制器page.password什麼代碼必須MD5

+0

你試過什麼或你只是在等人爲你寫代碼? –

回答

0

沒有在我的腳本中使用jQuery的,你可以改變,如果你想通過jQuery提交功能....我這樣做是沒有的jQuery

public function saveData(){ 
    $this->form_validation->set_rules ("oldpassword", "Old Password", "trim|required|xss_clean|callback_passwordCheck"); 
    $this->form_validation->set_rules ("newpassword", "New Password", "trim|required|matches[repassword]|xss_clean|min_length[5]"); 
    $this->form_validation->set_rules ("repassword", "Confirm Password", "trim|required|xss_clean"); 
    if ($this->form_validation->run() == false) { 
     $this->updatePassword(); 
    }else{ 
     $md5pass = $this->input->post('newpassword'); 
     $data ['username'] = $this->session->userdata ('username'); 
     $data ['password'] = md5($md5pass); 

     $this->load->model('loginModel'); 
     $this->loginModel->updatePassword('username',$data ['username'],$data); 

     //var_dump($data); 
    } 
} 

public function passwordCheck(){ 
    $username = $this->session->userdata ('username'); 
    $md5pass = $this->input->post('oldpassword'); 
    $this->load->model('loginModel'); 
    $results = $this->loginModel->getOldPassword($username); 
    $currentPass = $results->password; 

    if($md5pass==$currentPass){ 
     return true; 
    }else{ 
     $this->form_validation->set_message('passwordCheck', 'Invalid current password, please try again'); 
     return false; 
    } 
} 

<?php echo form_open("loginController/savedata",'class="cmxform form-horizontal tasi-form" id="commentForm"')?>

  <div class="form-group"> 
       <label class="col-sm-2 control-label">Old Password</label> 
       <div class="col-sm-10"> 
       <?=form_input($fldoldPassword) ?> 
       </div> 
      </div> 
      <div class="form-group"> 
       <label class="col-sm-2 control-label">New Password</label> 
       <div class="col-sm-10"> 
       <?=form_input($fldNewPassword) ?> 
       </div> 
      </div> 
      <div class="form-group"> 
       <label class="col-sm-2 control-label">Confirm Password</label> 
       <div class="col-sm-10"> 
       <?=form_input($fldRePassword) ?> 
       </div> 
      </div> 
      <div class="form-group"> 
       <label class="col-sm-2 control-label">&nbsp;</label> 
       <div class="col-sm-10"> 
       <button class="btn btn-danger" type="submit">Save</button> 
       <button class="btn btn-default" type="button">Cancel</button> 
       </div> 
      </div> 
      <div class="form-group"> 
       <label class="col-sm-2 control-label">&nbsp;</label> 
       <div class="col-sm-10"> 
       <?=validation_errors('<p class="alert alert-block alert-danger fade in">'); ?> 
       </div> 
      </div> 
      </form>