donglin7979 2015-02-16 04:31
浏览 53
已采纳

我想根据用户选择显示表单元素

Based on the user selection I want to show the form elements.Here the user selects class1,class6,engg. How do I bring the all form element in one common form right know I am having different form and form field for class 1,6. I am struggling to solve this issue.I don't know How to fix this.

My questions Are:

  1. If user select class1 I have list class1 form?
  2. If User select class2 I have to combine class1 and class6 under one form.
  3. Like wise user select class1,class2,class6,engg. I want to make all the form elments under one form.
  4. I have given my output sample?

    My FORM

    <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>
    

My PHP VALUES

   <?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
    }
    }
    }
    ?>

**I want output like this:**For class1 form:
<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>
****I want output like this:**For class1, class6 form:**
<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>

Like this the I want to make the form base on user selection.If user selected the all three classes(1,6,8), class 1 has different subject,like wise class 6 is different subject and engg has different subject.Now many problem is if user picks class(1,6,8),like wise class(1,6). How do I combine all the form element under one form and has one submit button

  • 写回答

2条回答 默认 最新

  • dongwei3712 2015-02-16 12:01
    关注
    if(count($product) == 1){
        if($product[0]=='class1'){
            echo "class one form";
        }else{
            echo "class other forms";
        }  
    }elseif(count($product) == 2){
        if($product[0]=='class1' && $product[1]=='class6'){
            echo "class one and class 6 form";
        }else{
            echo "class other forms";
        }
    }elseif(count($product) == 3){
        if($product[0]=='class1' && $product[1]=='class6' && $product[2]=='class8'){
            echo "class 1,6,8 form";
        }else{
            echo "class other forms";
        }       
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计