Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.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
PHP表单提交时自动跳转到HTML锚_Php_Html_Forms_Anchorpoint - Fatal编程技术网

PHP表单提交时自动跳转到HTML锚

PHP表单提交时自动跳转到HTML锚,php,html,forms,anchorpoint,Php,Html,Forms,Anchorpoint,我正在尝试将一个表单添加到我的索引页面中,这样当您单击submit时,它将在页面重新加载时自动返回表单。现在,如果页面上有任何错误,它将在表单的正上方显示这些错误,并给出一条小小的感谢信息 我目前在index.html页面上有以下内容: <?php include "check.php"; ?> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"&

我正在尝试将一个表单添加到我的索引页面中,这样当您单击submit时,它将在页面重新加载时自动返回表单。现在,如果页面上有任何错误,它将在表单的正上方显示这些错误,并给出一条小小的感谢信息

我目前在index.html页面上有以下内容:

<?php
    include "check.php";
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    Name:<br/> <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="30" /><br/><br/>
    Email Address:<br/> <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="30"/> <br/><br/>
    Company Name:<br/> <input type="text" name="companyName" value="<?php echo $_POST['companyname']; ?>" size="30" /> <br/><br/>
    Message:<br/>
    <textarea style="resize: none;" name="message" rows="5" cols="30"><?php echo $_POST['message']; ?></textarea>
    <br/>
    <input type="submit" name="Submit" />
</form>


当我提交页面时,它将运行check.php文件并验证所有数据是否正确。然后,如果满足所有条件,它应该返回以下If/then语句

if (!$errors) {
    $mail_to = 'test@test.com';
    $subject = 'New Mail from Form Submission';
    $message  = 'From: ' . $_POST['name'] . "\n";
    $message .= 'Email: ' . $_POST['email'] . "\n";
    $message .= 'Company Name: ' . $_POST['companyname'] . "\n";
    $message .= "Message:\n" . $_POST['message'] . "\n\n";
    mail($mail_to, $subject, $message);

    echo "Thank you for your email!<br/><br/>";
    $_POST = array(); //Clear form after submit

} else {
    echo '<div style="color: red">' . $errors . '<br/></div>';
}
if(!$errors){
$mail\u至test@test.com';
$subject='newmail from Form Submission';
$message='From:'.$\u POST['name']。“\n”;
$message.='Email:'.$\u POST['Email']。“\n”;
$message.=“公司名称:”。$\u POST['companyname']。“\n”;
$message.=“message:\n”。$\u POST['message']。“\n\n”;
邮件($mail_to,$subject,$message);
echo“感谢您的电子邮件!

”; $\u POST=array();//提交后清除表单 }否则{ 回显“.$errors.”
; }
在“谢谢”或“错误”回音中是否有自动添加功能,自动将此人带回联系人表单


我希望我正确地解释了我想做的事情。如果没有,请让我知道,我会尽量澄清一点。

在表单中添加一个ID,并将锚添加到表单操作URL上


在表单操作中添加“#锚定名称”可以实现以下目的。。。或者我遗漏了什么?请你把这个标记为正确答案:)