dongzang5815 2014-06-16 08:46
浏览 76
已采纳

PHP,是否可以在form2中使用form1,而action1不刷新form2

this is simple multi select form which select users and pass to input users

<form method="post" action="">
    <input name='input1' type='text'/>
    <input name='input2' type='text'/>
    <input name='input3' type='text'/>
    <select name="user[]" multiple="multiple" ondblclick="this.form.submit()">
        <option value="1">user1</option>
        <option value="2">user2</option>
        <option value="3">user3</option>
    </select>
    <input  type="text" name='selectedusers' value="<?php
      if (isset($_POST['user'])){
        $con = $_POST['user'];
        foreach($con as $user_single)
            echo '-'.$user_single; }
        ?> "/>
    <input type="Submit" value="abc" name="abc" />
</form>

now here the idea is to keep the input1, 2 and 3 which was input lastly, and make select. but here if i use multi select the previous input gets blank.

How i can keep the previous input values and make multi select pass the selected value to input name selectedusers and submit form..

regards

  • 写回答

2条回答 默认 最新

  • du8980919 2014-06-16 09:16
    关注

    I dont think HTML standards allow nesting of forms. I had once ran into the same scenario and i saw this in http://www.w3.org/TR/html5/forms.html#the-form-element .

    Content model: Flow content, but with no form element descendants.

    i.e. html denies nesting of form elements. So, is it not possible to have form1 inside form2.

    But you can use multiple submits inside the same form. and you can distinguish between the submits by the "name" and "value" attribute.

    <form>
    <input type="submit" name="submit" value="Submit 1" />
    <input type="submit" name="submit" value="Submit 2" />
    
    </form>
    
    <?php
    
    if(isset($_POST['submit']) and $_POST['submit']=="Submit 1")
    {
    ...
    }
    
    if(isset($_POST['submit']) and $_POST['submit']=="Submit 2")
    {
    ...
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序