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 关于#ar#的问题:/* User can add his own implementation to report the HAL error return state */(语言-c语言)
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败