Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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 表格won';t使用锚节进行验证_Javascript_Php_Forms_Validation - Fatal编程技术网

Javascript 表格won';t使用锚节进行验证

Javascript 表格won';t使用锚节进行验证,javascript,php,forms,validation,Javascript,Php,Forms,Validation,我在一个独立的联系人表单上有一个表单,但是当我试图在滚动页面的底部或带有锚的部分使用它时,它不会进行视觉验证。换句话说,错误消息不会出现。如果填写了所有必填字段,表单将发送一封电子邮件。但从视觉上看什么都没有发生!? 要了解它应该如何工作,请查看一个独立的contact.php patrickmchugh.com/test/contact.php这是错误消息应该如何工作的 <?php // check for form submission - if it doesn't exis

我在一个独立的联系人表单上有一个表单,但是当我试图在滚动页面的底部或带有锚的部分使用它时,它不会进行视觉验证。换句话说,错误消息不会出现。如果填写了所有必填字段,表单将发送一封电子邮件。但从视觉上看什么都没有发生!?

要了解它应该如何工作,请查看一个独立的contact.php patrickmchugh.com/test/contact.php这是错误消息应该如何工作的

<?php   
// check for form submission - if it doesn't exist then send back to contact form  
if (!isset($_POST['save']) || $_POST['save'] != 'contact') { 
    header('Location: index.php#content'); exit; 
} 

// get the posted data 
$name = $_POST['contact_name']; 
$email_address = $_POST['contact_email']; 
$subject = $_POST['contact_subject'];
$message = $_POST['contact_message']; 

// check that a name was entered 
if (empty($name)) 
    $error = 'You must enter your name.'; 
// check that an email address was entered 
elseif (empty($email_address))  
    $error = 'You must enter your email address.'; 
// check for a valid email address 
elseif (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email_address)) 
    $error = 'You must enter a valid email address.'; 
// check that a message was entered 
elseif (empty($message)) 
    $error = 'You must enter a message.'; 

// check if an error was found - if there was, send the user back to the form 
if (isset($error)) { 
    header('Location: index.php?e='.urlencode($error).'#content2'); exit;
} 

// write the email content 
$email_content = "Name: $name\n"; 
$email_content .= "Email Address: $email_address\n"; 
$email_content .= "Subject: $subject\n";
$email_content .= "Message:\n\n$message"; 

// send the email 
mail ("patrick@patrickmchugh.com", "Enquiry from Connolly O'Neill Website", $email_content); 

// send the user back to the form 
header('Location: index.php?s='.urlencode('Thank you for your message.').'#contact2'); exit; 

提交表单后,您的url将是
?e=您+必须+输入+您的+姓名。#content2
因此 您需要在表单页面上获取并回显错误,如:-

if(isset($_GET['e'])) {
  echo $_GET['e'];  // or echo urldecode($_GET['e']);
}
成功提交后的相同,如:-

if(isset($_GET['s'])) {
  echo $_GET['s'];  // or echo urldecode($_GET['s']);
}

Rakesh Sharma我不明白,我是在交换代码还是只是添加这个?把我的代码放在你想显示错误和消息的地方,然后看到这样的结果??//如果(空($name))$error=“您必须输入您的姓名”,请检查是否输入了姓名;如果(isset($_-GET['e']){echo$_-GET['e'];//或echo-urldecode($_-GET['e'])}仅使用给定的代码,如抱歉,我将其放入php代码中。我意识到现在我需要把它放到索引文件中。非常感谢。谢谢