我正在尝试从链接中获取变量(基本上是隐形按钮),但是,当我到达重定向页面时,它始终与它显示的$ _POST变量相同。我已经检查过它是在for循环之前还是之后设置的,但事实并非如此。我还打印了for循环中的值,它们应该是不同的。我还尝试在使用后在重定向页面底部取消设置变量。我现在完全没有想法......该怎么办?
<form method="post" action="http://localhost:8888/wordpress/job-openings/view-job/">
<table>
<tr>
<th>Job ID</th>
<th>Position</th>
<th>Client</th>
<th>Recruiter</th>
</tr>
<? for($i = 0; $i < count($rowArray); $i++) { ?>
<? $positionStatus = $data->response->result->JobOpenings->row[$i]->FL[8]->content;
$recruitmentResponsible = $data->response->result->JobOpenings->row[$i]->FL[7]->content;
$recruitmentResponsibleTweak = current(explode("(", $recruitmentResponsible));
$job_opening_id = $data->response->result->JobOpenings->row[$i]->FL[0]->content;
$request_url = 'http://recruit.zoho.com/ats/private/json/JobOpenings/getRecordById?authtoken=xxx&scope=recruitapi&id=' . $job_opening_id;
if ($positionStatus == 'In-progress') {
?>
<tr>
<td>
<input type="hidden" name="job_id" value="<?php echo $request_url ?>" />
<button id="jobopening-link">
<? echo $data->response->result->JobOpenings->row[$i]->FL[4]->content; ?>
</button>
</td>
<td><? echo $data->response->result->JobOpenings->row[$i]->FL[5]->content; ?></td>
<td><? echo $data->response->result->JobOpenings->row[$i]->FL[6]->content; ?></td>
<td><? echo $recruitmentResponsibleTweak ?></td>
</tr>
<? }
} ?>
</table>
</form>
答案 0 :(得分:1)
首先,代码中没有$_POST
的引用。其次,你总是获得相同值的原因是因为你总是为隐藏的输入设置相同的确切名称,并且当发送表单时,你将只获得具有该名称的第一个输入。我的建议是,在for循环中移动form标签,这样你就可以创建多个表单,每个表单都有提交按钮和隐藏输入中的正确值:
<table>
<tr>
<th>Job ID</th>
<th>Position</th>
<th>Client</th>
<th>Recruiter</th>
</tr>
<? for($i = 0; $i < count($rowArray); $i++) { ?>
<form method="post" action="http://localhost:8888/wordpress/job-openings/view-job/">
<? $positionStatus = $data->response->result->JobOpenings->row[$i]->FL[8]->content;
$recruitmentResponsible = $data->response->result->JobOpenings->row[$i]->FL[7]->content;
$recruitmentResponsibleTweak = current(explode("(", $recruitmentResponsible));
$job_opening_id = $data->response->result->JobOpenings->row[$i]->FL[0]->content;
$request_url = 'http://recruit.zoho.com/ats/private/json/JobOpenings/getRecordById?authtoken=xxx&scope=recruitapi&id=' . $job_opening_id;
if ($positionStatus == 'In-progress') {
?>
<tr>
<td>
<input type="hidden" name="job_id" value="<?php echo $request_url ?>" />
<button id="jobopening-link">
<? echo $data->response->result->JobOpenings->row[$i]->FL[4]->content; ?>
</button>
</td>
<td><? echo $data->response->result->JobOpenings->row[$i]->FL[5]->content; ?></td>
<td><? echo $data->response->result->JobOpenings->row[$i]->FL[6]->content; ?></td>
<td><? echo $recruitmentResponsibleTweak ?></td>
</tr>
<? } ?>
</form>
<? } ?>
</table>
答案 1 :(得分:0)
和输入类型=&#34;提交&#34; ???
捕获$ _POST内容:
<?php
if (isset($_POST['job_id'])) {
echo 'Do something for this job Id.';
}
?>