0

我有一个表单,可以根据唯一的名称标签动态打印出名称。用于响应邀请。每个名称标签可以有多个用户,即夫妇、有孩子的夫妇等。对于每个名称,都有一个单选按钮,受邀者可以在其中选择他/她是否来参加聚会(值 1=不来,2=来)。对于一对夫妇来说,它可能看起来像这样:

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

这些被邀请者中的每一个都有一个用户 ID - 我需要使用用户 ID 进行响应。它的 HTML 如下所示:

<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>

这些名称将从 MySQL 中获取,并带有这 3 个人的唯一名称标签,fxMARHAN

这是一种动态形式 - 对于某些名称标签,将只有两个被邀请者,而对于其他名称标签,将有 3 或 4 个,等等。

我的问题是我无法就如何处理发布的数据提出解决方案,因此我可以确保响应是针对正确的用户 ID。

4

2 回答 2

2

所有你需要的是

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

因为您已经有了userid in key单选按钮名称name="response[1]"

于 2012-11-14T12:19:14.123 回答
0

只是一个想法:如何使每个输入的值类似于“answer-userId”。例如:

<input type="radio" value="1-333" id="no-3" name="response[]" /><br />

然后你可以用'-'分割php中的发布值并得到答案(1)和用户ID(333)。

于 2012-11-14T12:20:33.247 回答