簡體   English   中英

輸入的文本未經Codeigniter驗證

[英]input text is not validated by codeigniter

我有一個密碼更改表,提交時僅驗證了兩個輸入,而未驗證名稱為“ confirm-new-password”的輸入。 我怎么了

請幫我。

HTML和JS代碼

$(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']));

嘗試這個

$this->form_validation->set_rules('password', 'Password', 'required|matches[confirm-new-password]');
$this->form_validation->set_rules('confirm-new-password', 'Password Confirmation', 'required');

試試這個代碼:

$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]');

然后更改您的輸入名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM