dthtvk3666 2011-04-27 17:00
浏览 36
已采纳

当动态创建复选框名称时,如何检索复选框数组值?

I am dynamically creating forms based on values in a database. Each form element corresponds to a specific database entry, which includes the name, label, type, and (depending upon the type) possible values to be displayed with the form element.

The name value for each form element is set to the identity column value of the corresponding database entry.

I'm running into a problem when I am working with checkboxes, though. I'm trying to retrieve the array of selected values, but I am unable to retrieve more than one. I believe that this is because I am not properly setting the checkbox names to an array, but I am not certain.

Here is where I am generating the checkbox tags:

$answers = explode(',',$answerKey);
for($i=0; $i < count($answers); $i++) {
    $questionTag .= "<INPUT TYPE='checkbox' name='$id' value='$answers[$i]' />$answers[$i]";
    }

Yet when I post back my results, the results of $_POST["$id"] only returns the last value in the checkbox list.

Any suggestions would be appreciated!

  • 写回答

1条回答 默认 最新

  • dtbiszu7724 2011-04-27 17:03
    关注
    $questionTag .= "<INPUT TYPE='checkbox' name='".$id."[]' value='$answers[$i]' />$answers[$i]";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集