Php 隐藏窗体并使用if语句
我已经找了很多地方,找不到一个真正好的例子来说明我需要什么。我有一个按钮,提交时需要弹出一个表单。我在过去使用input=hidden名称完成了这项工作。然而,我正在尝试使用if语句,而不仅仅是一个变量。我会给你我的代码,希望你能帮助找出我到底做错了什么。您可以看到,我确实对某些语句使用了隐藏名称,但我真的不知道如何将其合并到if语句中Php 隐藏窗体并使用if语句,php,Php,我已经找了很多地方,找不到一个真正好的例子来说明我需要什么。我有一个按钮,提交时需要弹出一个表单。我在过去使用input=hidden名称完成了这项工作。然而,我正在尝试使用if语句,而不仅仅是一个变量。我会给你我的代码,希望你能帮助找出我到底做错了什么。您可以看到,我确实对某些语句使用了隐藏名称,但我真的不知道如何将其合并到if语句中 if($row[status] == 0) { print "<input type='image' src='images/rework-ticket.
if($row[status] == 0) { print "<input type='image' src='images/rework-ticket.png' alt='Rework' value='Rework' name='button' style='height:50px; width:50px; '>"; }
elseif($row[status] == "Rework (In Progress)") { print "<img src='images/rework-ticket.png' alt='Rework' style='height:50px; width:50px; '>"; }
print "<td align='center'>";
print "<form method='post' action='test2.php'>";
print "<input type='image' src='images/rework-ticket.png' alt='Add Rework Ticket' value='Enter Employee ID' name='button' style='height:50px; width:50px; '>";
print "<input type='hidden' name='proceed_to_rework' value='true'>";
print "<input type='hidden' name='invoice_number' value='$row[invoice_number]'>";
print "<input type='hidden' name='last_name' value='$row[last_name]'>";
print "<input type='hidden' name='status' value='$status'>";
print "Status:";
print "<td><select name='status' size='1'>";
if($status != NULL) { print "<option value='$status'>$status</option>"; }
if($status != "Parts Prep (In Progress)") { echo "<option value='Parts Prep (In Progress)'>Parts Prep (In Progress)</option>"; }
if($status != "Parts Prep (Complete)") { echo "<option value='Parts Prep (Complete)'>Parts Prep (Complete)</option>"; }
if($status != "Assembly (In Progress)") { echo "<option value='Assembly (In Progress)'>Assembly (In Progress)</option>"; }
if($status != "Assembly (Complete)") { echo "<option value='Assembly (Complete)'>Assembly (Complete)</option>"; }
if($status != "Finish (In Progress)") { echo "<option value='Finish (In Progress)'>Finish (In Progress)</option>"; }
if($status != "Finish (Complete)") { echo "<option value='Finish (Complete)'>Finish (Complete)</option>"; }
if($status != "Plumbing (In Progress)") { echo "<option value='Plumbing (In Progress)'>Plumbing (In Progress)</option>"; }
if($status != "Plumbing (Complete)") { echo "<option value='Plumbing (Complete)'>Plumbing (Complete)</option>"; }
print "</form>";
print "</td>";
if($row[status]==0){print”“;}
elseif($row[status]==“返工(正在进行)”){print”“;}
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“”;
打印“状态:”;
打印“”;
如果($status!=NULL){打印“$status”;}
如果($status!=“零件准备(进行中)”){echo“零件准备(进行中)”;}
如果($status!=“零件准备(完成)”){echo“零件准备(完成)”;}
if($status!=“程序集(正在进行)”){echo“程序集(正在进行)”;}
如果($status!=“Assembly(Complete)”{echo“Assembly(Complete)”;}
如果($status!=“Finish(In Progress)”{echo“Finish(In Progress)”;}
如果($status!=“Finish(Complete)”{echo“Finish(Complete)”;}
如果($status!=“管道(进行中)”){echo“管道(进行中)”;}
如果($status!=“管道(完成)”){echo“管道(完成)”;}
打印“”;
打印“”;
我非常感谢您对我如何不仅修复此代码,而且改进此问题的任何评论。您可以使用
if
语句,如下所示
<?php if (condition): ?>
<!-- HTML here -->
<?php if (anotherCondition): ?>
<!-- HTML here -->
<?php endif; ?>
<!-- HTML again -->
<?php if (anotherCondition): ?>
<!-- HTML here -->
<?php endif; ?>
<!-- HTML again -->
<?php endif; ?>
通过这种方式,您不必使用太多的print
语句
阅读。中的示例,使用数组代替if语句。如果您希望在将来添加更多选项,这也会有所帮助。另外,不要逐行输出HTML代码,而是尝试使用一条echo语句 如果要从POST检索状态值,请使用
$status=$\u POST['status']代码>优先于其他一切
写入$row[status]
时要小心,因为您使用的是常量。我没有修改它,但是如果您想改为$row[$status]
,请将$
添加到status
之前
if($row[status] == 0) {
echo '
<button type="button" id="Rework" >
<img src="images/rework-ticket.png" alt="Rework" style="height:50px; width:50px; "></img>
</button>';
} elseif($row[status] == "Rework (In Progress)") {
echo '
<button type="button" id="Rework" >
<img src="images/rework-ticket.png" alt="Rework" style="height:50px; width:50px; "></img>
</button>';
}
echo "
<td align='center'>
<form method='post' action='test2.php'>
<input type='image' src='images/rework-ticket.png' alt='Add Rework Ticket' value='Enter Employee ID' name='button' style='height:50px; width:50px; '>
<input type='hidden' name='proceed_to_rework' value='true'>
<input type='hidden' name='invoice_number' value='{$row[invoice_number]}'>
<input type='hidden' name='last_name' value='{$row[last_name]}'>
<input type='hidden' name='status' value='{$status}'>
Status:
<td><select name='status' size='1'>
";
$statusOptions = array(
NULL,
"Parts Prep (In Progress)",
"Parts Prep (Complete)",
"Assembly (In Progress)",
"Assembly (Complete)",
"Finish (In Progress)",
"Finish (Complete)",
"Plumbing (In Progress)",
"Plumbing (Complete)"
);
foreach($statusOptions as $option){
if($status != $option){
echo "<option value='{$option}'>{$option}</option>";
}
}
echo '</select>';
echo "</form>";
echo "</td>";
echo '
<script type="text/javascript">
function showDocument(){
document.getElementById("ReworkForm").style.visibility="visible";
}
window.onload = function(){
document.getElementById("ReworkForm").style.visibility="hidden";
document.getElementById("Rework").addEventListener("click", showDocument);
};
</script>
';
如果($row[status]==0){
回声'
';
}elseif($行[状态]=“返工(正在进行)”){
回声'
';
}
回声“
地位:
";
$statusOptions=array(
无效的
“零件准备(进行中)”,
“零件准备(完成)”,
“大会(进行中)”,
“组装(完成)”,
“完成(进行中)”,
“完成(完成)”,
"水管工程(进行中),,
“管道(完整)”
);
foreach($statusOptions作为$option){
如果($status!=$option){
回显“{$option}”;
}
}
回声';
回声“;
回声“;
回声'
函数showDocument(){
document.getElementById(“ReworkForm”).style.visibility=“visible”;
}
window.onload=函数(){
document.getElementById(“ReworkForm”).style.visibility=“hidden”;
document.getElementById(“返工”).addEventListener(“单击”,显示文档);
};
';
这真的很有帮助。但我仍然需要能够隐藏状态选项,直到按下返工按钮之后,才需要看到它。有没有办法做到这一点?也许你需要一点javascript。我编辑了答案,添加了一个返工按钮(在第一部分中,您有$row[status])和末尾的javascript代码。