我有這個刪除,現在在CodeIgniter添加管理員帳戶功能。但我希望它一起工作。有什麼辦法可以解決這個問題嗎?刪除和保存工作正確分離壽。兩種形式,一頁codeigniter
控制器:
public function index()
{
$this->load->library('form_validation');
// model aanroepen
$this->load->model('Admin_model', '', TRUE);
// see if there is post
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$username = $this->input->post("username");
$password = $this->input->post("password");
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() != FALSE) {
$new_admin = new Admin_model();
$new_admin->Admin_name = $username;
$new_admin->Admin_password = $password;
$this->Admin_model->save($new_admin);
}
}
if ($this->input->server('REQUEST_METHOD') == 'POST') {
$userid = $this->input->post("id_admin");
$this->Admin_model->delete($userid);
}
$tweets = $this->Admin_model->get_all();
$viewdata = [
"tweets" => $tweets
];
$this->load->view('admin/admin', $viewdata);
}
}
查看:
<?php echo validation_errors() ?>
<h1>Create new admin</h1>
<form action="" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username"/>
<br/>
<label for="password">Password</label>
<input type="password" id="password" name="password"/>
<button type="submit" id="admin_submit">Submit</button>
</form>
<h1>Delete admin</h1>
<?php foreach($tweets as $t): ?>
<?php echo "<p>" . $t['admin_name']."</p> "; ?>
<form action="" method="post">
<input type="text" name="id_admin" value="<?php echo $t['admin_id'] ?>" />
<button type="submit" name="delete">Delete</button>
</form>
<?php endforeach; ?>
什麼problrmü面臨或你得到哪個錯誤? – 2015-04-03 10:20:20
當我點擊刪除按鈕時,它會顯示驗證錯誤 – user3071261 2015-04-03 10:23:59