ユーザーが必要に応じてフォームフィールドを追加できるフォームがあります。phpを介して電子メールで値を投稿する必要がありますが、値ではなく「配列」として返され続けます。私は初心者で、問題を理解できません。
これがjavascriptです:
var counter = 1;
var limit = 50;
function addInput(divName){
if (counter == limit) {
alert("You have renter code hereeached the limit of adding " + counter + " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='myInputs[]'>";
document.getElementById(divName).appendChild(newdiv);
counter++;
}
}
これがhtmlフォームです(時間を節約するためにほとんどを削除しました):
<form id="teamreg" class="appnitro" method="post" action="teamreg.php" >
<input name="recipient" type="hidden" id="recipient" value="kim@ka-kingdesigns.com" />
<ul>
<li>
<h3>Contact Information</h3>
</li>
<li id="li_1" >
<label class="description" for="company">Company/Organization </label>
<div>
<input id="company" name="company" class="element text large" type="text" maxlength="255" value=""/>
</div>
</li>
<li id="li_3" >
<label class="description" for="contactname">Team Cooridinator</label>
<span>
<input id="element_2_1" name= "contactname_1" class="element text" maxlength="255" size="8" value=""/>
<label>First</label>
</span>
<span>
<input id="element_2_2" name= "contactname_2" class="element text" maxlength="255" size="14" value=""/>
<label>Last</label>
</span>
</li>
<li class="section_break">
<h3>Team Members</h3>
<p>Please list everyone planning on volunteering (including spouses, children, etc.)<br/>
</p>
</li>
<li>
<div id="dynamicInput">
Entry 1<br><input type="text" name="myInputs[]">
</div>
<input type="button" value="Add another text input" onClick="addInput('dynamicInput');">
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="421421" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</li>
</ul>
</form>
これがphpです:
header("location: registrationthankyou.html");
$company = $_POST['company'];
$coordinator = "{$_POST['contactname_1']} {$_POST['contactname_2']}";
$myInputs = $_POST['myInputs'];
foreach ($myInputs as $eachInput) {
echo $eachInput . "<br>";
}
$to = $_POST['recipient']; //"user@example.com";
$subject = "Day of Caring Team Registration".$_POST['subject'];
$comments = "
<strong>Company:</strong> {$company}<br>
<strong>Team Coordinator:</strong> {$coordinator} <br>
<strong>Team Members</strong> {$myInputs}<br><br>
mail($to,$subject,$comments,"From: $from\r\n"
."Reply-To: $from\r\n"
."Content-Type: text/html; charset=iso-8859-1\n"
."X-Mailer: PHP/" . phpversion());