I'm having a tough time getting this to work. Maybe my logic is all wrong, but I figure someone with more experience can help me.
I have a page "http://domain.com/account/settings" where users can edit their account information. When the form submits, it triggers the "settings_save" method. All is fine if the form submits successfully, however, in the event one of the field doesn't validate, the URL remains at "http://domain.com/account/settings_save" I actually want it to stay on http://domain.com/account/settings"
account.php controller
function settings() {
$data['records'] = $this->account_model->getAccountSettings("sam");
$this->load->view('account_settings_view', $data);
}
function settings_save() {
$this->load->library('validation');
$records['email'] = "trim|required|min_length[4]|xss_clean";
$records['gender'] = "trim|required|xss_clean";
$records['seeking'] = "trim|required|xss_clean";
$records['marital_status'] = "trim|required|xss_clean";
$records['kids'] = "trim|required|xss_clean";
$records['drinking'] = "trim|required|xss_clean";
$records['smoking'] = "trim|required|xss_clean";
$records['ethnicity'] = "trim|required|xss_clean";
$records['body_type'] = "trim|required|xss_clean";
$records['zipcode'] = "trim|required|min_length[5]|numeric|xss_clean";
$this->validation->set_rules($records);
if ($this->validation->run() == false)
{
$this->load->view('account_settings_view', $records);
}
else
{
$records = array();
$records['email'] = $this->validation->email;
$records['gender'] = $this->validation->gender;
$records['seeking'] = $this->validation->seeking;
$records['marital_status'] = $this->validation->marital_status;
$records['kids'] = $this->validation->kids;
$records['drinking'] = $this->validation->drinking;
$records['smoking'] = $this->validation->smoking;
$records['ethnicity'] = $this->validation->ethnicity;
$records['body_type'] = $this->validation->body_type;
$records['zipcode'] = $this->validation->zipcode;
$this->account_model->saveAccountSettings("sam", $records);
$this->session->set_flashdata('message', 'Done. You have added new task.');
redirect('account/settings');
//redirect('account/settings');
}
}
account_settings_view.php view
I have the following line:
<?=form_open('account/settings_save');?>