Welcome Guest, Not a member yet? Register   Sign In
Form validation returning FALSE
#1

(This post was last modified: 10-14-2017, 12:45 PM by dwlamb. Edit Reason: Additional methods tried. )

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:
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'$dataTRUE);
                
$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'$dataTRUE);
                
$this->load->view('view_login_template'$data);
            }    
        } else {
            
$data['inset_content']    = $this->load->view('login/inset_obtain_email_password_reset'$dataTRUE);
            
$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.
Reply


Messages In This Thread
Form validation returning FALSE - by dwlamb - 10-14-2017, 12:05 PM
RE: Form validation returning FALSE - by PaulD - 10-15-2017, 04:58 AM
RE: Form validation returning FALSE - by dwlamb - 10-15-2017, 10:23 AM
RE: Form validation returning FALSE - by dwlamb - 10-15-2017, 01:06 PM
RE: Form validation returning FALSE - by dwlamb - 10-15-2017, 06:45 PM
RE: Form validation returning FALSE - by gmgj - 04-17-2019, 11:38 AM
RE: Form validation returning FALSE - by gmgj - 04-30-2019, 03:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB