douya5331 2012-11-14 12:11
浏览 23
已采纳

在php中为每个用户创建2个无线电

I have a form that dynamically prints out names based on a unique name tag. To be used for responding on invitations. There can be multiple users for each name tag, i.e. couples, couples with children, etc. For each name there is a radio-button where the invitee can select whether he/she is coming to the party or not (has the value 1=not coming, 2=coming). It can look like this, for a couple:

Lady Mary S
I am not coming         - radio - value 1
I am coming             - radio - value 2

Mister Hans S
I am not coming         - radio - value 1
I am coming             - radio - value 2

Child of Mary & Hans S
I am not coming         - radio - value 1
I am coming             - radio - value 2

Each of these invitees has a user id - I need the reponse to be with the user id. The HTML for it looks like this:

<div>
<h1>Lady Mary S</h1>
<label for="no-1">I am not coming</label>
<input type="radio" value="1" id="no-1" name="response[1]" /><br />
<label for="yes-1">I am coming</label> 
<input type="radio" value="2" id="yes-1" name="response[1]" />
<input type="hidden" name="userid[]" value="1" />
</div>

<div>
<h1>Mister Hans S</h1>
<label for="no-2">I am not coming</label>
<input type="radio" value="1" id="no-2" name="response[2]" /><br />
<label for="yes-2">I am coming</label> 
<input type="radio" value="2" id="yes-2" name="response[2]" />
<input type="hidden" name="userid[]" value="2" />
</div>

<div>
<h1>Child of Mary & Hans S</h1>

<label for="no-3">I am not coming</label>
<input type="radio" value="1" id="no-3" name="response[3]" /><br />
<label for="yes-3">I am coming</label> 
<input type="radio" value="2" id="yes-3" name="response[3]" />
<input type="hidden" name="userid[]" value="3" />
</div>

These names will be fetched from MySQL with a unique nametag for these 3 people, f.x. MARHAN

This is a dynamic form - for some nametags there will only be two invitees and for other nametags there will be 3 or 4, etc.

My problems is that I cannot come up with a solution on how to handle the posted data so I can make sure the reponse is for the right user id.

  • 写回答

2条回答 默认 最新

  • dran0703 2012-11-14 12:19
    关注

    All you need is

    foreach($_POST['response'] as $userid => $value) {
          echo $userid.'-'.$value."<br>";
    }
    

    Because you already have userid in key of radio button name name="response[1]"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路