0

I have a form that I allows the user to create a list of names. I need to also allow them to designate an rsvp status for an event for each name.

Here is the section of the form:

<li>
<div id="dynamicInput">
          Name 1<br><input type="text" name="myInputs[]">   Attending Brunch? Yes<input name="attending[]" type="checkbox" value="Attending Brunch" />  No<input name="notattending[]" type="checkbox" value="Not Attending Brunch" /><br>
           Name 2<br><input type="text" name="myInputs[]">   Attending Brunch? Yes<input name="attending[]" type="checkbox" value="Attending Brunch" />  No<input name="notattending[]" type="checkbox" value="Not Attending Brunch" /><br>
            Name 3<br><input type="text" name="myInputs[]">   Attending Brunch? Yes<input name="attending[]" type="checkbox" value="Attending Brunch" />  No<input name="notattending[]" type="checkbox" value="Not Attending Brunch" /><br>
             Name 4<br><input type="text" name="myInputs[]">   Attending Brunch? Yes<input name="attending[]" type="checkbox" value="Attending Brunch" />  No<input name="notattending[]" type="checkbox" value="Not Attending Brunch" /><br>
              Name 5<br><input type="text" name="myInputs[]">   Attending Brunch? Yes<input name="attending[]" type="checkbox" value="Attending Brunch" />  No<input name="notattending[]" type="checkbox" value="Not Attending Brunch" /><br>
     </div>
     <input type="button" value="Add another volunteer" onClick="addInput('dynamicInput');">
 </li>

This is the php that is returning the information in an email:

$myInputs = $_POST['myInputs'];
foreach ($myInputs as $eachInput) {
     $message .= $eachInput . " - " ;
}

$attending = $_POST['attending'];
foreach ($attending as $moreInput) {
     $message .= $moreInput . "<br><br>";
}

$notattending = $_POST['notattending'];
foreach ($notattending as $moreInput) {
     $message .= $moreInput . "<br><br>";
}


$contact = $_POST['contact'];
$from = "$name <$email>";
$to = $_POST['recipient']; //"kim@ka-kingdesigns.com";
$subject = "Day of Caring Team Registration".$_POST['subject'];
$comments = "
<strong>Team Members</strong><br> {$message}<br><br>;

Right now it return info entered like this:

Team Members Kim - Attending Brunch - Donovan - - - - Not Attending Brunch

I need it to return like this:

Team Members
Kim - Attending Brunch
Donovan - Not Attending Brunch

Can anyone help?

4

1 回答 1

0

就目前情况而言,您正在遍历表单上的整个人名列表;然后您将遍历与会者列表;然后您将循环查看未参加者的列表。

我建议明确编号字段:

Name 1<br><input type="text" name="name_1">   
Attending Brunch? Yes<input name="attending_1" type="radio" value="Yes" />  
No<input name="attending_1" type="radio" value="No" /><br>

这使得处理数据变得更加容易:

$count = 1;

while (isset($_POST["name_" . $count])) {
    $message .= $_POST["name_" . $count] . " - " $_POST["attending_" . $count] . "\n";
}

(抱歉,如果语法有点不对劲——我整天都在写 perl,而且语法很接近,当我尝试切换回来时会引起问题)

如果你想使用 javascript 添加一个额外的条目,它只需要遍历表单以找到最高的现有条目,并使用下一个可用的数字来生成字段名称。

于 2012-06-08T18:19:20.710 回答