Hey everyone!
I’ve set up flexi_auth with ease on one of my sites, now I tried to set it up on my other one and I’m having some weird problems with the register form. I got it working on the first site by simply modifying some demo files to fit my needs and now trying to use the same ones for the new site I can’t seem to get the rules to validate. “$this->form_validation->run()” always returns FALSE in the register_account method of the auth_model, but it never sets the validation errors(regardless if there are errors or not).
If I simply do a TRUE check instead of $this->form_validation->run() the user will be registered normally(but there would be no error notices/validation obviously). So why is $this->form_validation->run() always returning FALSE and not setting any error messages?
auth_model.php
function register_account()
{
$this->load->library('form_validation');
// Set validation rules.
// The custom rules 'identity_available' and 'validate_password' can be found in '../libaries/MY_Form_validation.php'.
$validation_rules = array(
array('field' => 'register_email_address', 'label' => 'Email Address', 'rules' => 'required|valid_email|identity_available'),
array('field' => 'register_username', 'label' => 'Username', 'rules' => 'required|min_length[4]|identity_available'),
array('field' => 'register_password', 'label' => 'Password', 'rules' => 'required|validate_password'),
array('field' => 'register_confirm_password', 'label' => 'Confirm Password', 'rules' => 'required|matches[register_password]')
);
$this->form_validation->set_rules($validation_rules);
// Run the validation. ->>> it always gets stuck here
if ($this->form_validation->run())
{
// Get user login details from input.
$email = $this->input->post('register_email_address');
$username = $this->input->post('register_username');
$password = $this->input->post('register_password');
// Get user profile data from input.
// You can add whatever columns you need to customise user tables.
$profile_data = array(
);
// Set whether to instantly activate account.
// This var will be used twice, once for registration, then to check if to log the user in after registration.
$instant_activate = FALSE;
// The last 2 variables on the register function are optional, these variables allow you to:
// #1. Specify the group ID for the user to be added to (i.e. 'Moderator' / 'Public'), the default is set via the config file.
// #2. Set whether to automatically activate the account upon registration, default is FALSE.
// Note: An account activation email will be automatically sent if auto activate is FALSE, or if an activation time limit is set by the config file.
$response = $this->flexi_auth->insert_user($email, $username, $password, $profile_data, 2, $instant_activate);
if ($response)
{
// This is an example 'Welcome' email that could be sent to a new user upon registration.
// Bear in mind, if registration has been set to require the user activates their account, they will already be receiving an activation email.
// Therefore sending an additional email welcoming the user may be deemed unnecessary.
$email_data = array('identity' => $email);
$this->flexi_auth->send_email($email, 'Welcome', 'registration_welcome.tpl.php', $email_data);
// Note: The 'registration_welcome.tpl.php' template file is located in the '../views/includes/email/' directory defined by the config file.
###+++++++++++++++++###
// Save any public status or error messages (Whilst suppressing any admin messages) to CI's flash session data.
$this->session->set_flashdata('message', $this->flexi_auth->get_messages());
// This is an example of how to log the user into their account immeadiately after registering.
// This example would only be used if users do not have to authenticate their account via email upon registration.
if ($instant_activate && $this->flexi_auth->login($email, $password))
{
// Redirect user to public dashboard.
redirect('racun');
}
// Redirect user to login page
redirect('racun');
}
}
// Set validation errors. -> these are NEVER set
$this->data['message'] = validation_errors('', '');
return FALSE;
}
And before you ask, my field names are correct and the POST data is transmitted, it’s just that no validation takes place/it always returns false?