无法让jquery.multi .select.js验证并将选中的复选框传递给php
Cannot get jquery.multiple.select.js to validate and pass to php the boxes checked
我使用jquery.multi .select.js v1.1.0,无法验证并将输出传递给我的php邮件。我的目标是为我的网站的访问者从多个选项请求报价选择。到目前为止,我能够收到所有其他字段验证的电子邮件,但在电子邮件中,我收到"quote for: array",但没有选择。同样相关的是,即使电子邮件发出,我也没有在页面上得到成功或错误信息。有人能给我指路吗?我将在这里包含有问题的页面,http://cptest.info/h2contact375.html
这是验证js
var Contact = {
initialized: false,
initialize: function() {
if (this.initialized) return;
this.initialized = true;
this.build();
this.events();
},
build: function() {
this.validations();
},
events: function() {
},
validations: function() {
$("#contactForm").validate({
submitHandler: function(form) {
$.ajax({
type: "POST",
url: "js/contact-form.php",
data: {
"name": $("#contactForm #name").val(),
"email": $("#contactForm #email").val(),
"telephone": $("#contactForm #telephone").val(),
"message": $("#contactForm #message").val(),
"ms": $("#contactForm #ms").val()
},
dataType: "json",
success: function (data) {
if (data.response == "success") {
$("#contactSuccess").removeClass("hidden");
$("#contactError").addClass("hidden");
$("#contactForm #name, #contactForm #email, #contactForm #telephone, #contactForm #message, #contactForm #ms")
.val("")
.blur()
.closest(".control-group")
.removeClass("success")
.removeClass("error");
if(($("#contactSuccess").position().top - 80) < $(window).scrollTop()){
$("html, body").animate({
scrollTop: $("#contactSuccess").offset().top - 80
}, 300);
}
} else {
$("#contactError").removeClass("hidden");
$("#contactSuccess").addClass("hidden");
if(($("#contactError").position().top - 80) < $(window).scrollTop()){
$("html, body").animate({
scrollTop: $("#contactError").offset().top - 80
}, 300);
}
}
}
});
},
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
telephone: {
required: true
},
message: {
required: true
},
ms:{
required: true,
message: 'Please select at least one'
},
},
highlight: function (element) {
$(element)
.closest(".control-group")
.removeClass("success")
.addClass("error");
},
success: function (element) {
$(element)
.closest(".control-group")
.removeClass("error")
.addClass("success");
}
});
}
};
Contact.initialize();
这里是php
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message'])||
empty($_POST['telephone'])||
empty($_POST['ms']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!"; return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$telephone = $_POST['telephone'];
$ms = $_POST['ms'];
// create email body and send it
$to = "myemail@gmail.com";
// put your email
$email_subject = "Contact form submitted by: $name"; $email_body = "You have received a new message. 'n'n".
" Here are the details:'n 'nName: $name 'n ".
"Telephone: $telephone 'n" .
"Quote For: $ms 'n" .
"Email: $email_address'n Message: 'n $message";
//$headers = "From: me@youremail.com'n";
//$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers); return true;
?>
将name
赋给您的字段ms
,否则它将不会转到php,因为它标识的是名称而不是id,并且根据您的条件检查,它将始终显示No arguments提供!
<select id="ms" multiple="multiple" name="ms">
尝试使用$_REQUEST
在您的PHP,如果$_POST
不提供数据检查。
注意:没有添加样式,只是期望它向你的php发送数据,没有其他。
<?php
// check if fields passed are empty
print_r($_REQUEST);//it should display the send data
//rest of the code with request
演示您可以使用以下代码进行验证,以便验证插件不会忽略隐藏的<select>
元素。
奇迹发生在这一行:
ignore: ':hidden:not("#ms")',
添加到验证脚本
//AjaxCall Code
},
ignore: ':hidden:not("#ms")',
rules: {
//Rules and messages onwards
以上将修复验证的问题,
关于不发布的数据,<select>
标签中没有name=""
,所以添加一个,验证后,<select>
值将与<form>
中的其他输入一起发布
<select style="display: none;" name="ms" id="ms" multiple="multiple" >
相关文章:
- 如何创建php函数或任何脚本/jquery Javascript,使我能够获取与复选框关联的值并添加它们
- 从复选框 ajax php javascript 中检索值
- 使用 php 和 javascript Ajax 发送复选框值时遇到问题
- 在JAVASCRIPT中获取php选中的复选框值
- 如何发布单选和复选框选择?表单由php和js处理
- 如何通过jquery/ajax将复选框数据作为数组发送到php脚本
- 使用复选框筛选PHP
- 在PHP结果中添加复选框,并在一段时间后使用java逐个打开它们
- 为每个选中的复选框显示相同的问题集.(PHP和JS/Jquery)
- (php/jquery)根据另一个选中的复选框值隐藏和显示复选框
- 在php生成的页面上获取勾选复选框列表的动态方式
- PHP和JS-如何从选中的复选框中获取值并输入
- 将复选框输入从PHP传递到JavsScript
- 使用JavaScript添加复选框值PHP、MySQL和alertbox
- PHP-AJAX复选框过滤器使用数据标记属性
- 使用 jquery 和 php 动态禁用某些复选框选项
- 在一个页面中选中一个复选框 自动选择 在另一个页面中使用 PHP,JavaScript
- Javascript + PHP - 当用户选择要上传的文件时如何选中复选框
- AJAX 调用 PHP 复选框问题
- 使用复选框 php 过滤搜索