【问题标题】:input text is not validated by codeigniter输入文本未通过 codeigniter 验证
【发布时间】:2016-02-25 07:35:29
【问题描述】:

我有一个密码更改表单,提交时只有两个输入经过验证,名称为“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']));

【问题讨论】:

    标签: javascript php jquery codeigniter validation


    【解决方案1】:

    试试这个

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

    【讨论】:

      【解决方案2】:

      试试这个代码:

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

      然后更改您的输入名称。

      【讨论】:

        猜你喜欢
        • 2013-01-25
        • 2015-10-12
        • 1970-01-01
        • 2015-07-06
        • 1970-01-01
        • 2015-10-02
        • 1970-01-01
        • 2013-02-09
        • 1970-01-01
        相关资源
        最近更新 更多