我想在点击按钮时发送2个变量 到目前为止我的代码是:
HTML:
<?php
while ($Case=mysql_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$Case['SubmissionID']."</td>";
echo "<td>".$Case['AppID']."</td>";
echo "<td>".getFullNameApp($Case['AppID'])."</td>";
echo "<td>".getCourseName($Case['SubmissionCourseID'])."</td>";
echo "<td>".getDepartmentName($Case['SubmissionCourseID'])."</td>";
echo "<td>".DateFormat($Case['Date'])."</td>";
echo "<td>".$Case['SubmissionStatus']."</td>";
if ($Case['SubmissionStatus'] == 'Draft') {
echo "<form action='ApplicantApplyDetails.php' method='POST'>";
echo "<td><button type='submit' class='btn btn-success btn-xs' name='modifybtn' value='".array($Case['SubmissionID'], $Case['SubmissionCourseID'])."'>Modify</button></td>";
}
else {
echo "<td><button type='submit' class='btn btn-danger btn-xs disabled' disabled='disabled' name='modifybtndis' value=''>Modify</button></td>";
}
echo "</form>";
echo "</tr>";
}
mysql_close();
?>
PHP:
if (isset($_POST['modifybtn'])) {
$SubmissionID =$_POST['modifybtn'][0];
$CourseID = $_POST['modifybtn'][1];
echo $CourseID;
}
然后获取这些变量以进行进一步处理。那可能吗?我做过单个但没有数组。我的代码不起作用。我认为问题出在HTML部分,但我不知道如何修复它。任何提示?
答案 0 :(得分:1)
回答你的问题;您可以将数组转换为字符串:
$value = json_encode([$Case['SubmissionID'], $Case['SubmissionCourseID']]);
echo "<td><button type='submit' class='btn btn-success btn-xs' name='modifybtn' value='".$value."'>Modify</button></td>";
在阅读时将字符串转换回数组。
var_dump(json_decode($_POST['modifybtn'], true));
但是也可以选择提交隐藏字段:
<input type="hidden" name="courseid" value="<?= $Case['SubmissionCourseID']>">
只需使用:
var_dump($_POST);