我已经编写了一个人才联系表单,我已经使用了jQuery验证以及表单字段的自定义PHP验证。
在开发阶段,两者都在所有浏览器[不低于8]上进行了测试。
现在已经上线了。 从用法日志中我们发现在极少数情况下验证无法正常工作,可能在以下特定字段中。有些用户可以在不选择特定字段的情况下提交表单。
你能指出/建议问题出在哪里?我正在尝试联系那些以某种方式绕过验证并知道他们的设备上发生了什么以及他们的浏览器版本的用户。他们似乎也是非技术和真正的用户。因此,不太可能尝试通过表单输入进行黑客攻击。
感谢您的所有时间和精力
绕过的输入字段
<div class="BNF_input_row">
<label for="BNF_select_talent" class="BNF_input_label">
Select Your Talent (required)
</label>
<select multiple="true" tabindex="106" class="input" id="BNF_select_talent" value="" name="BNF_select_talent[]" onclick="addTalentScdriptOption()" onblur="addTalentScdriptOption()" >
<?php echo BNF_Booking::getTalentList(); ?>
</select>
</div>
js验证码
var vlidation_option ={
rules: {
BNF_your_name: {
required: true,
minlength: 2
},
BNF_your_comp: {
required: true,
minlength: 3
},
BNF_your_email: {
required: true,
email: true
},
BNF_your_phone: {
required: true,
},
'BNF_select_talent[]': {
required: true,
},
BNF_choose_format: {
required: true,
},
BNF_master_script: {
extension: "doc|docx"
},
},
messages: {
BNF_your_name: {
required: "Required",
minlength: jQuery.format("At least {0} characters required!")
},
BNF_your_comp: {
required: "Required",
minlength: jQuery.format("At least {0} characters required!")
},
BNF_your_email: {
required: "Required",
email: jQuery.format("that email is not valid!")
},
BNF_your_phone: {
required: "Required",
phoneUS: "Not valid phone number"
},
'BNF_select_talent[]': {
required: "Required",
},
BNF_choose_format: {
required: "Required",
},
BNF_master_script: {
extension: "only .doc and .docx files are accepted"
},
},
};
jQuery("#BNF_booking_form").validate(vlidation_option);
PHP验证
public static function verifyData($data){
$response = array();
$response['status'] = "";
$iserror = false;
if(!isset($data['name']) || trim($data['name']) == ''){
$response['status'] .= "Enter your name\n";
$iserror = TRUE;
}
if(!isset($data['comp']) || trim($data['comp']) == ''){
$response['status'] .= "Enter your company\n";
$iserror = TRUE;
}
if(!isset($data['email']) || trim($data['comp']) == ''){
$response['status'] .= "Enter your email\n";
$iserror = TRUE;
}
if(!isset($data['phone']) || trim($data['comp']) == ''){
$response['status'] .= "Enter your phone\n";
$iserror = TRUE;
}
if(!isset($data['talent']) || trim($data['comp']) == ''){
$response['status'] .= "Select talent(s) for the job\n";
$iserror = TRUE;
}
if(!isset($data['script']) || trim($data['comp']) == ''){
$response['status'] .= "Attach scripts for talents\n";
$iserror = TRUE;
}
if(!$iserror){
$response['status'] = "YES";
}
return $response;
}
答案 0 :(得分:0)
调试一下。
使用Firefox控制台+ Firebug。在Javascript中用
写出你的变量console.log("Testing var1: " + var1);
您将在控制台日志中看到它。
PS:另外,我不确定,但请检查验证选项。你真的确定你需要BNF_select_talent之后的方括号吗?
'BNF_select_talent[]': { <===
required: true,
},
'BNF_select_talent[]': { <===
required: "Required",
},
答案 1 :(得分:0)
对于PHP,看起来你需要修剪和验证人才而不是comp,试试这个:
替换它,
if(!isset($data['email']) || trim($data['comp']) == ''){
$response['status'] .= "Enter your email\n";
$iserror = TRUE;
}
if(!isset($data['phone']) || trim($data['comp']) == ''){
$response['status'] .= "Enter your phone\n";
$iserror = TRUE;
}
if(!isset($data['talent']) || trim($data['comp']) == ''){
$response['status'] .= "Select talent(s) for the job\n";
$iserror = TRUE;
}
if(!isset($data['script']) || trim($data['comp']) == ''){
$response['status'] .= "Attach scripts for talents\n";
$iserror = TRUE;
}
使用,
if(!isset($data['email']) || trim($data['email']) == ''){
$response['status'] .= "Enter your email\n";
$iserror = TRUE;
}
if(!isset($data['phone']) || trim($data['phone']) == ''){
$response['status'] .= "Enter your phone\n";
$iserror = TRUE;
}
if(!isset($data['talent']) || trim($data['talent']) == ''){
$response['status'] .= "Select talent(s) for the job\n";
$iserror = TRUE;
}
if(!isset($data['script']) || trim($data['script']) == ''){
$response['status'] .= "Attach scripts for talents\n";
$iserror = TRUE;
}
对于JS,试试这个:
$.validator.addMethod("talentRequired", function (value, element) {
var count = $(element).find('option:selected').length;
return count > 0;
});
并替换,
'BNF_select_talent[]': {
required: true,
},
使用,
'BNF_select_talent[]': "required talentRequired",