I am adding a delete button to certain rows of a table (not all). The table is already inside a form, so my thinking is to do a check to see if my button was clicked inside the function that the form submits to and redirect to a delete function if it was. I can't figure out if it's possible to do that or what other options there are.
I tried using a link for the delete, but that doesn't get the information across. I tried using another form, but that's a form within a form. If there is another way to do this, I'm happy to learn it.
Here is parts of the form:
echo '<form action="#/job/addorupdate" id="jobform" name="jobform" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="id" value="228828">';
if ($id > 0) {
echo '<button style="color:red;border:none;font-weight:bold;cursor:pointer;" type="submit" value="' . $id . '" name="idOfRow">X</button>';
}
echo '</form>';
Here is the function it goes to:
public function addOrUpdate(){ // addOrUpdate a job - control
if ($this->input->post('idOfRow')) {
// This is where I want to do the redirect
}
.
.
}
The solution was to replace the button with a link and use that to call the delete function.
echo ' <a href="' . site_url('#/deleteunrelatedcase/' . $jobid . '/' . $id) . '" style="color:red;font-weight:bold;">X</a>';
public function addOrUpdate(){ // addOrUpdate a job - control
if ($this->input->post('idOfRow')) {
$delete=deleteRow($this->input->post('idOfRow'));
if($delete == 1){
header('location:location.php'); // add redirect location here.
}
}
}
//Create One New function
public function deleteRow($DeleteInput){
if ($DeleteInput) {
//add sql function to delete
if(delete == true){
return 1;
}
else {
return false;
}
}
}