Answer the question
In order to leave comments, you need to log in
How to send success message after execution?
Good day.
Controller:
public function edit_user(){
if (!($this->userlib->logged_in())){
return redirect('admin/users/login');
}
$this->data['title'] = "Редактирование пользователя";
$this->data['css'] = array(
"assets/css/icons/icomoon/styles.css",
"assets/css/bootstrap.css",
"assets/css/core.css",
"assets/css/components.css",
"assets/css/colors.css"
);
$this->data['js'] = array(
"assets/js/plugins/loaders/pace.min.js",
"assets/js/core/libraries/jquery.min.js",
"assets/js/core/libraries/bootstrap.min.js",
"assets/js/core/libraries/jquery_ui/core.min.js",
"assets/js/core/app.js",
"assets/js/plugins/forms/selects/selectboxit.min.js",
"assets/js/pages/form_selectbox.js"
);
$data = array();
$url = current_url();
$user_id = (substr($url, 40, 30));
$this->form_validation->set_rules('login', 'Имя', 'trim|xss_clean|required');
$this->form_validation->set_rules('email', 'E-mail', 'trim|valid_email|xss_clean|required');
$this->form_validation->set_rules('password', 'Пароль', 'trim|xss_clean|min_length[6]|max_length[16]');
$this->form_validation->set_rules('status', 'Статус', 'trim|xss_clean|required');
if($this->form_validation->run()) {
$updateData = array(
'username' => $this->input->post('login'),
'email' => $this->input->post('email'),
);
if($this->input->post('password')) {
$updateData['password'] = sha1(md5($this->input->post('password')));
}
if($this->input->post('status') == 'admin'){
$updateData['status'] = "3";
} else if($this->input->post('status') == 'moder'){
$updateData['status'] = "2";
} else if($this->input->post('status') == 'user'){
$updateData['status'] = "1";
} else if($this->input->post('status') == 'banned'){
$updateData['status'] = "0";
}
if($this->user->updateItem($user_id, $updateData)) {
return redirect('admin/users');
$this->data['success'] = 'Данные обновлены.';
}
}
$this->data['user']= $this->user->getItem($user_id);
$this->load->view('admin/user/edit_user', $this->data);
}
if($this->user->updateItem($user_id, $updateData)) {
return redirect('admin/users');
$this->data['success'] = 'Данные обновлены.';
}
Answer the question
In order to leave comments, you need to log in
/**
* Redirect with POST data.
*
* @param string $url URL.
* @param array $post_data POST data. Example: array('foo' => 'var', 'id' => 123)
* @param array $headers Optional. Extra headers to send.
*/
public function redirect_post($url, array $data, array $headers = null) {
$params = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data)
)
);
if (!is_null($headers)) {
$params['http']['header'] = '';
foreach ($headers as $k => $v) {
$params['http']['header'] .= "$k: $v\n";
}
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if ($fp) {
echo @stream_get_contents($fp);
die();
} else {
// Error
throw new Exception("Error loading '$url', $php_errormsg");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question