on_before_validate hook semi-working

edited October 2011 in News & Announcements
Alright, here we are again :)
In the backend I've built a password verification system based on the user_model. However, whatever I do, the new_password field always gets saved (edit mode). My current code is looking like this. My is_valid_password() function works for other sections so it couldn't be the cause.

function form_fields($values = array()) { // .. code // unset password field, then set it again to list it at the bottom before the new password field // see fuel/models/user_model.php $pwd_field = $fields['password']; unset($fields['password']); $user_id = NULL; if (!empty($values['id'])) { $user_id = $values['id']; } if (!empty($user_id)) { $fields['new_password'] = array('label' => 'New password', 'type' => 'password'); } else { $pwd_field['type'] = 'password'; $pwd_field['order'] = 50; $pwd_field['label'] = 'Your password'; $fields['password']= $pwd_field; } $fields['confirm_password'] = array('label' => 'Repeat new password', 'type' => 'password', 'order' => 51); return $fields; } function on_before_validate($values) { $this->add_validation('email', 'valid_email', lang('error_invalid_email')); // for new if (empty($values['id'])) { // all this stuff works so removed code } // for editing else { if (isset($this->normalized_save_data['new_password'])) { $this->add_validation('new_password', array(&$this, 'is_valid_password'), 'Password is invalid'); } if (isset($this->normalized_save_data['new_password']) AND isset($this->normalized_save_data['confirm_password'])) { $this->get_validation()->add_rule('password', 'is_equal_to', lang('error_invalid_password_match'), array($this->normalized_save_data['new_password'], $this->normalized_save_data['confirm_password'])); //not working either: $this->get_validation()->add_rule('new_password', 'is_equal_to', lang('error_invalid_password_match'), array($this->normalized_save_data['new_password'], $this->normalized_save_data['confirm_password'])); } } return $values; }

Once again I call upon your knowledge. It is greatly appreciated. I don't really know how to troubleshoot this ...


  • edited 3:00PM
    So you are saying the validation you have in place isn't returning false when it should (the passwords don't match for instance)? Can you debug what is getting passed to the is_equal_to function (in the validator_helper functions)?
Sign In or Register to comment.