I am undertaking a migration of a project from CI 2.2.x to 3.1.6 and am stuck on validation of an e-mail address on a password reset form.
Below is my code. This works perfectly in 2.2.x but validation returns false in 3.1.6:
The problem seems to lie in the new methods for validation core/Form_validation.php public function run() line 422:
The $validation_array is set set correctly from the $_POST data but the _field_data array is empty.
I have tried setting rules using the array method and the cascade method as outlined in the Form Validation docs for 3.1.6 and they are not being set under core/Form_validation.php public function set_rules. CI sees no POST data $this->validation_data as empty.
Is there something I am missing?
Thanks for taking the time to read this.
Below is my code. This works perfectly in 2.2.x but validation returns false in 3.1.6:
PHP Code:
if (isset($_POST['email']) && !empty($_POST['email'])) {
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
if ($this->form_validation->run() == FALSE)
{
$data['errors'] = 'E-mail address you provided is not valid.';
$data['inset_content'] = $this->load->view('login/inset_obtain_email_password_reset', $data, TRUE);
$this->load->view('view_login_template', $data);
} else {
$email = trim($this->input->post('email'));
$user = $this->model_reset_password->email_exists($email);
if ($user) {
$this->send_reset_password_email($email,$user['first_name'],$user['salt']);
}
$data['inset_content'] = $this->load->view('login/inset_reset_password_email_sent', $data, TRUE);
$this->load->view('view_login_template', $data);
}
} else {
$data['inset_content'] = $this->load->view('login/inset_obtain_email_password_reset', $data, TRUE);
$this->load->view('view_login_template', $data);
}//if
The problem seems to lie in the new methods for validation core/Form_validation.php public function run() line 422:
PHP Code:
public function run($group = '')
{
$validation_array = empty($this->validation_data)
? $_POST
: $this->validation_data;
// Does the _field_data array containing the validation rules exist?
// If not, we look to see if they were assigned via a config file
if (count($this->_field_data) === 0)
{
// No validation rules? We're done...
if (count($this->_config_rules) === 0)
{
return FALSE;
}
...
The $validation_array is set set correctly from the $_POST data but the _field_data array is empty.
I have tried setting rules using the array method and the cascade method as outlined in the Form Validation docs for 3.1.6 and they are not being set under core/Form_validation.php public function set_rules. CI sees no POST data $this->validation_data as empty.
PHP Code:
public function set_rules($field, $label = '', $rules = array(), $errors = array())
{
// No reason to set rules if we have no POST data
// or a validation array has not been specified
if ($this->CI->input->method() !== 'post' && empty($this->validation_data))
{
return $this;
}
Is there something I am missing?
Thanks for taking the time to read this.