When the form doesn't get run because some of the fields are missing the form validator redirects back to current controller/method by default. This means that if I've set a route for 'signup' that routes to auth/register I want it to redirect back to the route path not the actual controller path.
Any suggestions?
function register() {
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'required|xss_clean');
$this->form_validation->set_rules('contact', 'Contact', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
if ($this->form_validation->run() == true) {
// Do some stuff here
} else {
$data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$data['name'] = array('name' => 'name',
'id' => 'name',
'type' => 'text',
'value' => $this->form_validation->set_value('name'),
);
$data['description'] = array('name' => 'description',
'id' => 'description',
'type' => 'textarea',
'value' => $this->form_validation->set_value('description'),
'class' => 'form-textarea',
);
$data['email'] = array('name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
);
$data['contact'] = array('name' => 'contact',
'id' => 'contact',
'type' => 'text',
'value' => $this->form_validation->set_value('contact'),
);
$data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
);
$data['password_confirm'] = array('name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
);
$this->load->view('organisations/create', $data);
}
}