duanhuang4306 2015-12-04 14:57
浏览 36

当我的按钮在表单之外时,获取复选框的值

I have some problem with a form which contains foreach and I input submit button outside of form (out of foreach) but when i select checkboxes, it get only first checkbox!!! how it can be done ? Thanks

Remarque: I can't put the form around foreach.

{foreach from=$aWSForServer2 key=ws item=webservice}
    <form action="index.php" method="post" onSubmit="return confirm('{$i18n.confirm_suppress}')" id="FormDelSelWS" >
    <input type="hidden" name="view_mode" value="{$view_mode}" />
    <input type="hidden" name="action" value="del_sel_ws" />
    <input type="hidden" name="idServer" value="{$server_id}" />
    <input type="checkbox" name="WSSelcet[]" value="{$webservice.Webservice__}" />
   </form>
{/foreach}
<table style="width:620px;margin:5px;">
  <tr>
   <td style="width:300px"></td>
   <td style="width:140px"></td>
   <td style="width:160px"></td>
    <td>
   <button type="submit" value="{$i18n.suppress}" form="FormDelSelWS">
    supprimer</button>
  </td>
 </tr>
  </table>
  • 写回答

1条回答 默认 最新

  • dtpd58676 2015-12-04 16:00
    关注
    • A form control cannot be associated with multiple forms
    • An ID must be unique in a document (so you can't generate multiple forms with the same ID in a loop).

    You need to rethink your logic, probably to include a single form.

    It isn't clear which of the values changes in your loop, but it looks like only the checkbox does. If so, you just need to move your loop inside the form.

    <form action="index.php" method="post" onSubmit="return confirm('{$i18n.confirm_suppress}')">
        <input type="hidden" name="view_mode" value="{$view_mode}" />
        <input type="hidden" name="action" value="del_sel_ws" />
        <input type="hidden" name="idServer" value="{$server_id}" />
    
        {foreach from=$aWSForServer2 key=ws item=webservice}
            <input type="checkbox" name="WSSelcet[]" value="{$webservice.Webservice__}" />
        {/foreach}
    
        <button type="submit" value="{$i18n.suppress}">
            supprimer
        </button>
    

    If any of the other values change in your loop, and need to be associated with a particular submit button then you can either:

    • Just keep them on the server and look them up with the checkbox values
    • Encode them in the form associated with the checkbox name (and then look them up on the server, but in $_POST.

    Such:

    <input type="hidden" name="idServer[{$webservice.Webservice__}]" value="{$server_id}" />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100