Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我的表单验证工作正常,但有时提交时似乎是空白的_Javascript_Php_Jquery_Forms_Validation - Fatal编程技术网

Javascript 我的表单验证工作正常,但有时提交时似乎是空白的

Javascript 我的表单验证工作正常,但有时提交时似乎是空白的,javascript,php,jquery,forms,validation,Javascript,Php,Jquery,Forms,Validation,我的表单具有JavaScript验证,当字段为空时,该验证将返回错误并停止表单提交。“” 我还在后端进行PHP验证,检查是否有空字段 提交将发送一封包含字段的电子邮件 在测试中,所有验证都是有效的。正确填写后,表格连同所有信息一起提交 我每天大约收到一封空白电子邮件。提交如何绕过我的JavaScript和PHP验证 我的表格: <form id="itsp-form" method="post" action="http://www.website.com/save_itsp.php"&g

我的表单具有JavaScript验证,当字段为空时,该验证将返回错误并停止表单提交。“”

我还在后端进行PHP验证,检查是否有空字段

提交将发送一封包含字段的电子邮件

在测试中,所有验证都是有效的。正确填写后,表格连同所有信息一起提交

我每天大约收到一封空白电子邮件。提交如何绕过我的JavaScript和PHP验证

我的表格:

<form id="itsp-form" method="post" action="http://www.website.com/save_itsp.php">
<label class="custom">Company name</label>
<input id="company_name" type="text" name="company_name" />

<label class="custom">Company URL</label>
<input id="company_url" type="text" name="company_url" />

<label class="custom">Company address</label>
<input id="company_address" type="text" name="company_address" />

<label class="custom">Type of business</label>
<select id="type_of_business[]" name="type_of_business[]" multiple="multiple">
  <option value="enterprise">Business sector/Enterprise</option>
  <option value="residential">Residential</option>
  <option value="wholesale">Wholesale VoIP Carrier</option>
  <option value="other">Other</option>
</select>

<label class="custom">Areas served</label>
<select id="areas_served[]" name="areas_served[]" multiple="multiple">
  <option value="USA">USA</option>
  <option value="Canada">Canada</option>
  <option value="other">Other</option>
</select>

<br />

<label class="custom">Sales contact</label><br />
<h4>Name</h4>
  <input id="sales_name" type="text" name="sales_name" />
<h4>Phone</h4>
  <input type="text" name="sales_phone" />
<h4>Email</h4>
  <input type="text" name="sales_email" />

<br />

<label class="custom">Testing contact</label><br />
<h4>Name</h4>
  <input id="testing_name" type="text" name="testing_name" />
<h4>Phone</h4>
  <input type="text" name="testing_phone" />
<h4>Email</h4>
  <input type="text" name="testing_email" />

<br />

<label class="custom">Switch Platform</label>
<select id="switch_platform[]" name="switch_platform[]" multiple="multiple">
  <option value="asterisk">Asterisk</option>
  <option value="broadsoft">Broadsoft</option>
  <option value="metaswitch">Metaswitch</option>
  <option value="sipx">SipX/eZuce</option>
  <option value="other">Other</option>
</select>

<label class="custom">Interested In Testing</label>
<select id="interested_in_testing[]" name="interested_in_testing[]" multiple="multiple">
  <option value="atas">ATAs</option>
  <option value="ip_phones">IP Phones</option>
  <option value="gateways">Gateways</option>
  <option value="ip_pbx">IP PBX</option>
</select>

<input type="submit" id="submit" value="Submit" />

</form>
<div id="errors"></div>
</div>
 <script>
  $('#submit').click(function() {
    $('.error').hide();

    var hasError = false;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

    if (($("#company_name").val() == '') || ($("#type_of_business[]").val() == '')) {
       $("#errors").after('<span class="error">Please enter your Company name.</span>');
       hasError = true;
    }
    if (($("#company_url").val() == '') || ($("#company_address").val() == '')) {
       $("#errors").after('<span class="error">Please enter your Company information.</span>');
       hasError = true;
    }
    if ($("#areas_served[]").length < 0) {
       $("#errors").after('<span class="error">Please enter your Areas served.</span>');
       hasError = true;
    }
    if ($("#type_of_business[]").length < 0) {
       $("#errors").after('<span class="error">Please enter your Type of business.</span>');
       hasError = true;
    }
    if ($("#sales_name").val() == '') {
       $("#errors").after('<span class="error">Please enter your Sales contact information.</span>');
       hasError = true;
    }
    if ($("#testing_name").val() == '') {
       $("#errors").after('<span class="error">Please enter your Tester contact information</span>');
       hasError = true;
    }
    if ($("#switch_platform[]").length < 0) {
       $("#errors").after('<span class="error">Please enter your Switch platform</span>');
       hasError = true;
    }
    if ($("#interested_in_testing[]").length < 0) {
       $("#errors").after('<span class="error">Please enter your Testing interests.</span>');
       hasError = true;
    }
  if(hasError == true) { return false; }
});

公司名称
公司网址
公司地址
业务类型
商界/企业
住宅的
批发VoIP运营商
其他
服务区域
美国
加拿大
其他

销售联系人
名称 电话 电子邮件
测试触点
名称 电话 电子邮件
交换平台 星号 博德软 元开关 SipX/eZuce 其他 对测试感兴趣 阿塔斯 IP电话 通道 IP交换机 $(“#提交”)。单击(函数(){ $('.error').hide(); var hasError=false; var emailReg=/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; 如果($(“#公司名称”).val()='')|($(“#业务类型[]”).val()=''){ $(“#错误”)。在('请输入您的公司名称')之后; hasrerror=true; } 如果($(“#公司地址”).val()='')|($(“#公司地址”).val()=''){ $(“#错误”)。之后('请输入您的公司信息'); hasrerror=true; } if($(“#服务区域[]”)。长度<0){ $(“#错误”)。之后('请输入您的服务区域'); hasrerror=true; } if($(“#业务类型[]”)长度<0){ $(“#错误”)。之后('请输入您的业务类型'); hasrerror=true; } 如果($(“#销售名称”).val()=''){ $(“#错误”)。之后('请输入您的销售联系信息'); hasrerror=true; } if($(“#测试名称”).val()=''){ $(“#错误”)。之后('请输入您的测试仪联系信息'); hasrerror=true; } if($(“#交换机_平台[]”)长度<0){ $(“#错误”)。在('请输入您的交换平台')之后; hasrerror=true; } if($(“#对#u测试感兴趣[]”)。长度<0){ $(“#错误”)。之后('请输入您的测试兴趣'); hasrerror=true; } 如果(hasError==true){return false;} });

我的PHP文件:

function died($error) {
// your error code can go here
echo "We are very sorry, but there were blank fields found with the form you
   submitted. ";
$link_address = 'http://www.website.com/url/itsp';
echo "<a href='".$link_address."'>Click to Go Back<br/></a>";
die();
}


if (isset($_POST['company_name'])) 
{
$errors = "";

//validate and sanitize company name
if ($_POST['company_name'] != "")
{
  $_POST['company_name'] = filter_var($_POST['company_name'], FILTER_SANITIZE_STRING);
  $company_name = $_POST['company_name'];
}
else 
died();

//validate and sanitize company url
if ($_POST['company_url'] != "")
{
  $_POST['company_url'] = filter_var($_POST['company_url'], FILTER_SANITIZE_STRING);
  $company_url = $_POST['company_url'];
}
else
    died();
//validate and sanitize company address
if ($_POST['company_address'] != "")
{
  $_POST['company_address'] = filter_var($_POST['company_address'], FILTER_SANITIZE_STRING);
  $company_address = $_POST['company_address'];
}
else
    died();
if (is_array($_POST['type_of_business']) && !empty($_POST['type_of_business'])) {
    $type_of_business_val = array();
    foreach($_POST['type_of_business'] as $val) {
        $type_of_business_val[] = $val;
    }
    $type_of_business = implode(',', $type_of_business_val);
}
else
    died();
if (is_array($_POST['areas_served']) && !empty($_POST['areas_served'])) {
    $areas_served_val = array();
    foreach($_POST['areas_served'] as $val) {
        $areas_served_val[] = $val;
    }
    $areas_served = implode(',', $areas_served_val);
}
else
    died();
//validate and sanitize sales name
if ($_POST['sales_name'] != "")
{
  $_POST['sales_name'] = filter_var($_POST['sales_name'], FILTER_SANITIZE_STRING);
  $sales_name = $_POST['sales_name'];
}
else
    died();
//validate and sanitize sales email
if ($_POST['sales_email'] != "")
{
  $sales_email = filter_var($_POST['sales_email'], FILTER_SANITIZE_EMAIL);
  if (!filter_var($sales_email, FILTER_VALIDATE_EMAIL)) {
      $errors .= "$sales_email is <strong>NOT</strong> a valid email address.<br/><br/>";
  }
}
else
    died();
//validate and sanitize sales phone number
if ($_POST['sales_phone'] != "")
{
  $_POST['sales_phone'] = filter_var($_POST['sales_phone'], FILTER_SANITIZE_STRING);
  $sales_phone = $_POST['sales_phone'];
}
else
    died();
//validate and sanitize testing name
if ($_POST['testing_name'] != "")
{
  $_POST['testing_name'] = filter_var($_POST['testing_name'], FILTER_SANITIZE_STRING);
  $testing_name = $_POST['testing_name'];
}
else
    died();
//validate and sanitize testing email
if ($_POST['testing_email'] != "")
{
  $testing_email = filter_var($_POST['testing_email'], FILTER_SANITIZE_EMAIL);
  if (!filter_var($testing_email, FILTER_VALIDATE_EMAIL)) {
      $errors .= "$testing_email is <strong>NOT</strong> a valid email address.<br/><br/>";
  }
}
else
    died();
if ($_POST['testing_phone'] != "")
{
  $_POST['testing_phone'] = filter_var($_POST['testing_phone'], FILTER_SANITIZE_STRING);
  $testing_phone = $_POST['testing_phone'];
}
else
    died();
if (is_array($_POST['switch_platform']) && !empty($_POST['switch_platform'])) 
{
    $switch_platform_val = array();
    foreach($_POST['switch_platform'] as $val) {
        $switch_platform_val[] = $val;
    }
    $switch_platform = implode(',', $switch_platform_val);
}
else
    died();

if (is_array($_POST['interested_in_testing']) && !empty($_POST['interested_in_testing'])) {
    $interested_in_testing_val = array();
    foreach($_POST['interested_in_testing'] as $val) {
        $interested_in_testing_val[] = $val;
    }
    $interested_in_testing = implode(',', $interested_in_testing_val);
}
else
    died();
 }
 /************** End Validations *******************/

 /*****Email*****/
$to = "email";
$subject = "New ITSP Submission";
$message1 = "A new ITSP has submitted their information:
<br/>Company Name: " . $company_name . "
<br/>Company URL: " . $company_url . "
<br/>Company Address: " . $company_address . "
<br/>Type of Business: " . $type_of_business . "
<br/>Area(s) Served: " . $areas_served . "
<br/>Sales Name: " . $sales_name . "
<br/>Sales Email: " . $sales_email . "
<br/>Sales Phone: " . $sales_phone . "
<br/>Testing Name: " . $testing_name . "
<br/>Testing Email: " . $testing_email . "
<br/>Testing Phone: " . $testing_phone . "
<br/>Switch Platform: " . $switch_platform . "
<br/>Interested In Testing: " . $interested_in_testing ;


$headers = "MIME-Version: 1.0\n";

mail($to,$subject,$message1,$headers);
header("location: http://www.website.com/dir/itsp-confirmation/");
函数失效($error){
//您的错误代码可以转到这里
echo“非常抱歉,您的表单中有空白字段
提交。”;
$link\u地址=http://www.website.com/url/itsp';
回声“;
模具();
}
如果(isset($_POST['company_name']))
{
$errors=“”;
//验证并清理公司名称
如果($\u POST['company\u name']!=“”)
{
$\u POST['company\u name']=filter\u var($\u POST['company\u name'],filter\u SANITIZE\u STRING);
$company\u name=$\u POST['company\u name'];
}
其他的
死亡();
//验证并清理公司url
如果($\u POST['company\u url']!=“”)
{
$\u POST['company\u url']=filter\u var($\u POST['company\u url'],filter\u SANITIZE\u STRING);
$company\u url=$\u POST['company\u url'];
}
其他的
死亡();
//验证并清理公司地址
如果($\u POST['company\u address']!=“”)
{
$\u POST['company\u address']=filter\u var($\u POST['company\u address'],filter\u SANITIZE\u STRING);
$company\u address=$\u POST['company\u address'];
}
其他的
死亡();
if(是数组($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\{
$type_of_business_val=array();
foreach($邮政['type\ u of\ u business']作为$val){
$type_of_business_val[]=$val;
}
$type_of_business=内爆(“,”,$type_of_business\u val);
}
其他的
死亡();
if(是数组($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\{
$areas_served_val=array();
foreach($_POST['areased']作为$val){
$areas_served_val[]=$val;
}
$areas_served=内爆(',',$areas_served_val);
}
其他的
死亡();
//验证并清理销售名称
如果($\u POST['sales\u name']!=“”)
{
$\u POST['sales\u name']=filter\u var($\u POST['sales\u name'],filter\u SANITIZE\u STRING);
$sales\u name=$\u POST['sales\u name'];
}
其他的
死亡();
//验证和清理销售电子邮件
如果($\u POST['sales\u email']!=“”)
{
$sales\u email=filter\u var($\u POST['sales\u email'],filter\u SANITIZE\u email);
if(!filter_var($sales_email,filter_VALIDATE_email)){
$errors.=“$sales_电子邮件不是有效的电子邮件地址。

”; } } 其他的 死亡(); //验证并清理销售电话号码 如果($\u POST['sales\u phone']!=“”) { $\u POST['sales\u phone']=filter\u var($\u POST['sales\u phone'],filter\u SANITIZE\u STRING); $sales\u phone=$\u POST['sales\u phone']; } 其他的 死亡(); //验证和清理测试名称 如果($\u POST['testing\u name']!=“”) { $\u POST['testing\u name']=filter\u var($\u POST['testing\u name'],filter\u SANITIZE\u STRING); $testing\u name=$\u POST['testing\u name']; } 其他的 死亡(); //验证和清理测试电子邮件 如果($\u POST['testing\u email']!=“”) { $testing\u email=filter\u var($\u POST['testing\u email'],filter\u SANITIZE\u email); if(!filter_var($testing_email,filter_VALIDATE_email)){ $errors.=“$testing_电子邮件不是有效的电子邮件地址。

”; } } 其他的 死亡(); 如果($\u POST['testing\u phone']!=“”) { $\u POST['testing\u phone']=filter\u var($\u POST['testing\u phone'],filter\u SANITIZE\u STRING); $testing_phone=$_POST['testing_phone']; } 其他的 死亡(); if(是数组($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ { $switch_platform_val=array(); foreach($_POST['switch_platform']作为$val){ $switch_platform_val[]=$val; } $switch_platform=内爆(“,”,$switch_platform_val); } 其他的 死亡(); if(is_数组($_POST['interest_in_testing'])和($_POST['interest_in_testing'])为空($_POST['interest_in_testing'])){ $interest_in_testing_val=array(); foreach($作为$val发布['对测试感兴趣]){ $interest_in_testing_val[]=$val; } $interest_in_testing=内爆(',
if ($_POST['sales_email'] != "")
{
  $sales_email = filter_var($_POST['sales_email'], FILTER_SANITIZE_EMAIL);
  if (!filter_var($sales_email, FILTER_VALIDATE_EMAIL)) {
      $errors .= "$sales_email is <strong>NOT</strong> a valid email address.<br/><br/>";
      died();
  }
}
else
    died();