根据用户选择我想显示表单元素。在这里,用户选择class1
,class6
,engg
。如何将所有表单元素置于一个通用表单中,知道我对于1,6类具有不同的表单和表单字段。
我的问题是:
我的表格
<form name="frm" method="post">
<table align="center">
<tr>
<td>Name</td>
<td><input type="text" name="txt" id="txt" required ></td><td></td>
</tr>
<tr>
<td>Product</td>
<td>
<input type="checkbox" name="chk[]" value="class1">class1
<input type="checkbox" name="chk[]" value="class6">class6
<input type="checkbox" name="chk[]" value="class8">class8
<input type="checkbox" name="chk[]" value="class10">class10
<input type="checkbox" name="chk[]" value="class12">class12
<input type="checkbox" name="chk[]" value="engineering">engineering
<input type="checkbox" name="chk[]" value="technology">technology
</td><td></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Save"></td><td></td>
</tr>
</table>
</form>
我的PHP值
<?php
if (isset($_POST['submit']))
{
$name = $_POST['txt'];
$product = $_POST['chk'];
print_r($product);
foreach($product as $k=> $v)
{
if($v=="class1")
{
?>
<form name="f1" action="" method="post">
<p>class1
<input type="checkbox" name="chk[]" value="allsubject">allsubject
<input type="checkbox" name="chk[]" value="science">science
<input type="checkbox" name="chk[]" value="maths">maths
</p>
<input type="submit" name="submit" value="submit">
</form>
<?php
}
if($v=="class1" && $v="class6")
{
?>
<form name="f1" action="" method="post">
<p>class1</p>
<input type="checkbox" name="chk[]" value="allsubject">allsubject
<input type="checkbox" name="chk[]" value="science">science
<input type="checkbox" name="chk[]" value="maths">maths
<p>class6</p>
<input type="checkbox" name="chk[]" value="allsubject">allsubject
<input type="checkbox" name="chk[]" value="science">science
<input type="checkbox" name="chk[]" value="maths">maths
<input type="text" name="name" value="">Tutor Name
<input type="text" name="name" value="">Tutor Address
<input type="submit" name="submit" value="submit">
</form>
<?php
}
}
}
?>
我想要这样的输出:
对于class1表格:
<form name="f1" action="" method="post">
<p>class1
<input type="checkbox" name="chk[]" value="allsubject">allsubject
<input type="checkbox" name="chk[]" value="science">science
<input type="checkbox" name="chk[]" value="maths">maths
</p>
<input type="submit" name="submit" value="submit">
</form>
对于class1,class6形式:
<form name="f1" action="" method="post">
<p>class1</p>
<input type="checkbox" name="chk[]" value="allsubject">allsubject
<input type="checkbox" name="chk[]" value="science">science
<input type="checkbox" name="chk[]" value="maths">maths
<p>class6</p>
<input type="checkbox" name="chk[]" value="allsubject">allsubject
<input type="checkbox" name="chk[]" value="science">science
<input type="checkbox" name="chk[]" value="maths">maths
<input type="text" name="name" value="">Tutor Name
<input type="text" name="name" value="">Tutor Address
<input type="submit" name="submit" value="submit">
</form>