我在视图中有一个复选框列表,这些复选框是通过 foreach 循环生成的form_checkbox('jobseeker[]', $application['jobseeker_profile_id']);
。
目前我有 2 行由此生成,但点击提交按钮时似乎有问题。当我在检查生成的第一个复选框后点击提交按钮时,我收到一个错误Undefined variable: candidates
和 foreach 错误,当我在检查两个复选框生成后点击提交按钮时,我收到一个错误Undefined variable: candidates
,但是当我只检查第二个复选框时,我没有收到任何错误,它确实它应该在下一页做什么。
我在问我当前的代码有什么问题会阻止多个复选框被单击而不会出错?
复选框视图
foreach($applications as $application){
$value = $application['points_value'] * $this->session->userdata('price');
echo "<tr class=\"row\" style=\"background: green\">";
echo "<td class=\"column\">";
echo $application['name'];
echo "</td>";
echo "<td class=\"column\">";
foreach($skills as $myskills){
echo $myskills[$i]['name'];
}
echo "</td>";
echo "<td class=\"column\">";
foreach($qualifications as $myqualifications){
echo $myqualifications[$i]['name'];
}
echo "</td>";
echo "<td class=\"column\">";
foreach($workhistory as $myhistory){
echo $myhistory[$i]['role'];
}
echo "</td>";
echo "<td class=\"column\">";
echo form_open('resume');
echo form_hidden('jobseeker_id', $application['jobseeker_profile_id']);
echo form_submit('submit'.'" class="submitButton"', 'View CV');
echo form_close();
echo "</td>";
echo "<td class=\"column\">";
echo $value;
echo "</td>";
echo "<td class=\"column\">";
echo form_open('applications/interview');
echo form_checkbox('jobseeker[]', $application['jobseeker_profile_id']);
echo "</td>";
echo "</tr>";
$i++;
}
echo form_submit('Submit'.'" class="submitButton"', 'Continue');
echo form_close();
控制器
$this->load->view('header');
$applicants = $this->input->post('jobseeker');
$data = array();
foreach($applicants as $applicant => $id){
$data['candidate'] = $this->db->get_where('jobseeker_profiles', array('id' => $id ))->row_array();
$data['candidates'][] = $data['candidate'];
}
$this->load->view('payment', $data);
输出视图
foreach($candidates as $candidate){
$value = $candidate['total_points_value'] * $this->session->userdata('price');
echo $candidate['name']." - "."£".number_format($value, 2, '.', '');
$total += $value;
}
echo "<br><br>";
echo "Total Payment: £".number_format($total, 2, '.', '');
echo form_open('applications/payment');
echo form_hidden('amount'.'" value="'.$total.'');
echo form_submit('submit'.'" class="submitButton"', 'Make Payment');
echo form_close();
非常感谢。