I am using codeigniter with shield and i have a edit userpage, in the controller I have
public function update($id)
{
$users = auth()->getProvider();
$user = $users->findById($id);
if ($this->validate($rules))
{
$user->fill([
'username' => $this->request->getPost('username'),
'email' => $this->request->getPost('email'),
'status' => $this->request->getPost('isBanned')
]);
$users->save($user);
return redirect()->to("admin/dashboard/manage-users")
->with("message", "User updated.");
}
return redirect()->back()
->with("errors", $this->validator->getErrors())
->withInput();
}
In the data base there is a field called status by default it is Null
I want to change the status to Banned if checked if unchecked set back to null
The only way I have been able to get this to semi work is the following
<div>
<input type="checkbox" id="isBanned" name="isBanned" value="banned" <?= set_checkbox('status', 'banned') ?>>
<input type="checkbox" id="isBanned" name="isBanned" value="NULL" <?= set_checkbox('status', 'NULL') ?>>
<label for="isBanned">Banned</label>
</div>
I would like to be able to use only 1 checkbox on if the user is banned it stays checked until i uncheck it