[英]Is it possible to redirect to another function within a function in PHP?
我在表的某些行(不是全部)中添加了删除按钮。 该表已经存在于表单中,因此我的想法是进行检查以查看是否在表单提交到的函数中单击了我的按钮,然后单击该按钮并重定向到删除函数。 我不知道是否有可能这样做,或者还有其他选择。
我尝试使用链接进行删除,但这并不能传达信息。 我尝试使用其他表单,但这是表单中的表单。 如果还有其他方法可以做到,那么我很高兴学习。
这是表格的一部分:
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>';
这是它要执行的功能:
public function addOrUpdate(){ // addOrUpdate a job - control
if ($this->input->post('idOfRow')) {
// This is where I want to do the redirect
}
.
.
}
解决方案是用链接替换按钮,然后使用该链接调用删除功能。
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.