大家好,我很难弄清楚什么是错的。 所以我有一个电子邮件发送表单复选框和复选框限制,但是,它无法正常工作。 这是复选框限制脚本。
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++){
if(document.form1.ckb[i].checked){
total =total +1;}
if(total > 3){
alert("Please Select only three")
document.form1.ckb[j].checked = false ;
return false;
}
}
} </script>
这是表格
<form name="form1" method="post" action="send_form_email2.php">
<tr bgcolor=''#ffffcc''><td > </td><td ><b>Išsirinkite viena ar daugiau produktus.
</b></td></tr><br>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=multi mama balzamas
onclick='chkcontrol(0)';></td><td >Multi-Mama Balzamas</td></tr><br>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=multi mama kompresai
onclick='chkcontrol(1)';></td><td >Multi-Mama kompresai</td></tr><br>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=multi gyn actigel
onclick='chkcontrol(2)';></td><td >Multi-Gyn ActiGel</td></tr><br>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=multi gyn liquigel
onclick='chkcontrol(3)';></td><td >Multi-Gyn LiquiGel</td></tr><br>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=multi oral gel
onclick='chkcontrol(4)';></td><td >Multi-Oral Gel</td></tr><br>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=Multi-Oral Remi Dent
onclick='chkcontrol(5)';></td><td >Multi-Oral Remi Dent</td></tr><br>
<tr bgcolor=''#f1f1f1'' ><td ><input type=checkbox name=ckb value=Maxiderma Rankom
onclick='chkcontrol(6)';></td><td >Maxiderma Rankom</td></tr><br>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=Maxiderma Kojom
onclick='chkcontrol(7)';></td><td >Maxiderma Kojom</td></tr><br>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=Physiosalt
onclick='chkcontrol(8)';></td><td >Physiosalt</td></tr><br>
<tr bgcolor=''#ffffff'' ><td ><input type=checkbox name=ckb value=AquaBloc
onclick='chkcontrol(9)';></td><td >AquaBloc</td></tr><br>
<p><table width="561">
<tr>
<td width="212" align="right" valign="top">
<label for="name">*Vardas</label>
</td>
<td width="337" valign="top">
<input type="text" name="name" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="company">*Pavardė</label>
</td>
<td width="337" valign="top">
<input type="text" name="name" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="telephone">*Miestas</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="email">*El.paštas</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="180" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="ckb"><br />
</label>
</td>
<td valign="top">
</td>
</tr>
<tr>
<td width="212" align="right" valign="top">
<label for="name">*Gatvė, namo Nr., buto Nr:</label>
</td>
<td width="337" valign="top">
<input type="text" name="name" maxlength="150" size="50">
</td>
</tr>
<tr>
<td width="212" align="right" valign="top">
<label for="name">*Pašto kodas</label>
</td>
<td width="337" valign="top">
<input type="text" name="name" maxlength="150" size="50">
</td>
</tr>
<tr>
<td valign="top" align="right">
<label for="comments">*Komentaras</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="40" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<center><input type="submit" VALUE=" Siusti " id="submit_button" disabled></center>
<input type="checkbox" id="TOS" value="1" onClick="agreeTerms(this)"> Sutinku su
taisyklemis. <a target="_blank" href="siuntimo.html" rel="nofollow" >Taisykles</a><br>
</p>
</td>
</tr>
</table>
</form>
这是php电子邮件表单
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
if(isset($_POST['email'])) {
$cbk = array();
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@samplebox.eu";
$email_subject = "Contact form";
$email_from = "";
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Vardas: ".clean_string($_POST["name"])."\n";
$email_message .= "El. Pastas: ".clean_string($_POST["email"])."\n";
$email_message .= "Telephone: ".clean_string($_POST["telephone"])."\n";
$email_message .= "Produktai: ".implode(" ", $_POST['ckb'])."\n";
$email_message .= "Comments: ".clean_string($_POST["comments"])."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<center>
<img src="images/logo.png" />
<br>
<br>
Greitai susisieksime<br>
<br>
<a href="index.html">Namai</a></center>
<?php
}
?>
当选中这些复选框时,当您点击提交按钮时,我会收到一封包含所有信息的电子邮件,除非它没有显示选中的复选框。
任何人都可以帮我吗? :) 编辑:这是
中的以下代码<script type="text/javascript">
var myForm = document.forms.form1;
var allInputs= myForm.elements['ckb[]'];
var len = allInputs.length;
for (var i = 0; i < len; i++)
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++){
if(document.form1.ckb[i].checked){
total =total +1;}
if(total > 3){
alert("Please Select only three")
document.form1.ckb[j].checked = false ;
return false;
}
}
}
} </script>
答案 0 :(得分:0)
谷歌搜索后,我发现有人试图做类似的事情。我想你需要改变
name=ckb
到
name=ckb[]
所以php会知道&#34; ckb&#34;确实是一系列复选框。 希望这有助于
发表你的评论试试这个:
var allInputs = document.form1.elements['ckb[]'];
var len = allInputs.length;
for (var i = 0; i < len; i++)
your code here
}
我们聊了很多,结果发现html本身有一些问题,并没有调用这些函数,但上面的代码毕竟是有用的。