我有一个 HTML 表单。我有一些 jQuery 动画(对话框弹出和验证)将数据发送到form.php
.
我的问题:我收到了包含 NAME、EMAIL 和 PHONE 的电子邮件,但只通过了一个选项。多选都选不出来。。。
有人能帮助我吗?
所以这是我的代码:
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>
这是 HTML 页面顶部的 jQuery:
$(文档).ready(函数() {
$('#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 = 'w-productions@hotmail.com';
$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);
?>