Question

Okay so im attempt to allow users to change their passwords via an admin panel with this code but i keep getting

ORM_Validation_Exception [ 0 ]: Failed to validate array ~ MODPATH/orm/classes/kohana/orm.php [ 1174 ]

Anyone have any solutions? heres the controller function and model functions and view respectively

Controller:

public function action_edituser() {
    $this->auto_render = false;

    $edit = Model::factory('manageusers');

    $post = $_POST;

    $edit->editUser($post);
}

Model:

public function editUser($array) {
    try {
        $user = ORM::factory('user')
                ->where('id', '=', $array['id'])
                ->find()
                ->update_user($array, array(
            'username',
            'password',
            'email',
                ));
        return $this->response('success', 'User Edited');
    } catch (Database_Exception $e) {
        $this->response('error', $e->getMessage());
    }
}

View:

<div class="modal" id="editmodal" style="display: none;">
    <div class="modal-header">
        <a class="close" data-dismiss="modal">×</a>
        <h3>Edit User</h3>
    </div>
    <div class="modal-body">
        <?php
        echo Form::open('admin/manageusers/edituser', array('data-function'=> '/admin/manageusers/updategrid', 'data-element' => 'tbody'));

        echo Form::label('username', 'Username');
        echo Form::input('username', null, array('id' => 'username'));

        echo Form::label('email', 'Email');
        echo Form::input('email', null, array('id' => 'email'));

        echo HTML::anchor('#', 'Change Password', array('id' => 'changepass', 'style' => 'display: block;'));
        echo '<div id="passwordchange" style="display: none;">';

        echo Form::label('password', 'Password');
        echo Form::password('password', null, array('id'  => 'password'));

        echo Form::label('password_confirm', 'Confirm Password');
        echo Form::password('password_confirm');
        echo '</div>';
        echo Form::hidden('id', null, array('id' => 'id'));
        ?>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">Close</a>
        <input type="submit" class="btn btn-success" value="Save changes" />
    </div>
    <?php echo Form::close(); ?>
</div>
Was it helpful?

Solution

The problem is that there are validation errors, meaning your input does not match the rules of your model.

You need to catch ORM_Validation_Exceptions, and figure out what causes the error.

public function editUser($array) {
    try {
        ...
    } catch (Database_Exception $e) {
        ...
    } catch (ORM_Validation_Exception $e) {
        var_dump($e->errors());
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top