我有一个密码更改表单,当提交时,只有两个输入被验证并输入名称" confirm-new-password"未经过验证。我错了什么?
请帮帮我。
HTML和JS CODE
$(function($) {
$.fn.ajaxForm = function(url, data, msgHolderId) {
var self = this;
var result;
return $(self).bind('submit', function(e) {
e.preventDefault();
if (data != null)
data = "&" + $.param(data);
alert(data);
$.ajax({
url: '<?= base_url() ?>' + url,
async: false,
cache: false,
data: $(self).serialize() + data,
type: 'POST',
dataType: 'json',
success: function(response) {
$('#' + msgHolderId).html(response.msg);
}
});
});
}
}(jQuery));
$(document).ready(function() {
$('#password-change-form').ajaxForm('user/settings/password_change', null, 'msg-holder');
});
我的HTML表格
<form id="password-change-form">
<table class="table table-bordered table-responsive table-condensed table-hover">
<tr>
<td colspan="3" style="background-color: #e8e8e8">Password Update</td>
</tr>
<tr>
<td style="width:20%">Current password</td>
<td style="width:50%"><input type="password" class="form-control" name="current-password" id="current-password" /></td>
<td></td>
</tr>
<tr>
<td style="width:20%">New Password</td>
<td style="width:50%"><input type="password" class="form-control" name="new-password" id="new-password" /></td>
<td></td>
</tr>
<tr>
<td style="width:20%">Confirm new password</td>
<td style="width:50%"><input type="password" class="form-control" name="confirm-new-password" id="confirm-new-password" /></td>
<td></td>
</tr>
<tr>
<td style="width:20%"></td>
<td colspan="2" style="width:50%"><input type="submit" class="btn btn-default" value="ذخیره تغییرات" /></td>
</tr>
</table>
</form>
服务器端代码
$this->form_validation->set_rules('current-password', 'A', 'trim|callback_password_check');
$this->form_validation->set_rules('new-password', 'B', 'trim|required|min_length[8]');
$this->form_validation->set_rules('confirm-new-password', 'C', 'trim|matches[new-password]');
if($this->form_validation->run())
$this->Common_db_actions_model->update_data('users' ,array('password' => $hash_new_password) ,array('user_id' => $this->active_user['user_id']));
答案 0 :(得分:1)
试试这个
$this->form_validation->set_rules('password', 'Password', 'required|matches[confirm-new-password]');
$this->form_validation->set_rules('confirm-new-password', 'Password Confirmation', 'required');
答案 1 :(得分:0)
试试这段代码:
$this->form_validation->set_rules('current_pwd', 'Current password','required');
$this->form_validation->set_rules('new_pwd', 'New password' ,'required|min_length[6]|max_length[20]');
$this->form_validation->set_rules('confirm_pwd', 'Confirm password','required|matches[new_pwd]');
然后更改您的输入名称。