我有一个HTML表单。我有一些jQuery动画(对话框弹出和验证),将数据发送到form.php
。通过jQuery选项多选PHP选择插件
我的问题:我收到我的电子邮件名称,电子邮件和电话,但只有一个选项通过。我无法得到多种选择...
有人可以帮我吗?
因此,这里是我的代码:
HTML
<form class="form_class" id="form_id" method="POST" name="contactform" action="form.php">
<label for="nom">Name</label>
<br/>
<input name="nom" type="text" id="nom" /><br/>
<label for="email">Email</label>
<br/>
<input name="email" type="text" id="email" /><br/>
<label for="tel">Phone</label>
<br/>
<input name="tel" type="text" id="tel" /><br/>
<select multiple="multiple" name="beats[]" data-placeholder="Choose your beats" id="beats" style="width:300px;" tabindex="4">
<option name="AlternateFunkyDelicBeat" value="AlternateFunkyDelicBeat"> AlternateFunkyDelicBeat</option>
<option name="Bottom" value="Bottom"> Bottom</option>
<option name="Free_Speech" value="Free_Speech"> Free Speech</option>
<option name="Fuck_Friends" value="Fuck_Friends"> Fuck Friends</option>
<option name="Hopeless_Streets" value="Hopeless_Streets"> Hopeless Streets</option>
<option name="If_I_Die_Tonight" value="If_I_Die_Tonight"> If I Die Tonight</option>
<option name="Infamous" value="Infamous"> Infamous</option>
<option name="Obvious_Behavior" value="Obvious_Behavior"> Obvious Behavior</option>
<option name="Off_The_Flight" value="Off_The_Flight"> Off The Flight</option>
<option name="Pissed" value="Pissed"> Pissed</option>
</select>
<input type="image" src="images/button.png" id="button" width="100" height="56" target="_parent"/></form>
这里是jQuery的在HTML页面的顶部:
$(文件)。就绪(函数(){
$('#form_id').submit(function(){
nom = $(this).find("#nom").val();
email = $(this).find("#email").val();
tel = $(this).find("#tel").val();
/*beats = $(this).find("#beats").val();*/
beats = $(this).find("#beats").val();
$.post('form.php',{
nom:nom,
email:email,
tel:tel,
beats:beats
}, function(data){
if(data.error =='mail_invalide'){
$('#basic-modal-content2').modal();
return false;
}else if(data.error =='vide'){
$('#basic-modal-content1').modal();
return false;
}else{
$('#basic-modal-content3').modal({onClose: function(){
$("input").val('');
$("textarea").val('');
$.modal.close();
}});
return false;
}
}, "json");
return false;
});
});
</script>
最后,我form.php的
<?php
$e = array();
$e['error'] = "Non valid form";
if(empty($_POST['nom']) || empty($_POST['tel'])){
$e['error'] = "vide";
}
elseif(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$e['error'] = "mail_invalide";
}
else{
$e['error'] = 'Ok';
$nom = $_POST['nom'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$beats = $_POST['beats'];
$to = '[email protected]';
$sujet = 'New message from W-Productions.com '.$email;
$body = "New message from W-Productions.com \n\n
Name: $nom \n
Emali: $email \n
Phone: $tel \n\n
Beats: $beats";
mail($to, $sujet, $body);
}
echo json_encode($e);
?>
谢谢!完美的事情! – 2013-05-04 15:43:37