如何在刷新前使站点重定向到同一页面 - PHP
How to make site redirect to same page before refreshing - PHP
我试图让用户在刷新之前重定向回 #contact page
。但是,当单击发送消息时,网站会返回到第一页,我必须一直向下滚动到 #contact page
,然后 5 秒后它会刷新回第一页(这很好)。我的代码如下:
PHP
<?php
if($_POST['submit']){
if(!$_POST['name']){
$error= "<br/>-Please enter your name" ;
}
if(!$_POST['email']){
$error.= "<br/>-Please enter your email" ;
}
if (trim($_POST['message']) == "")
{
$error.= "<br/>-Please enter message";
}
if(!$_POST['contact']!=$match){
$error.= "<br/>-Please enter your contact number" ;
}
if ($error){
$result= "Whoops, error: $error";
}
else{
mail('mahdi.mashrafi@yahoo.com', "Contact message", "Name: ".$_POST['name']." Email: ".$_POST['email']."
Email: ".$_POST['name']."
Message : ".$_POST['message']."
Contact :".$_POST['contact'] );
// header("location:index.php#contact");
header( "refresh:5; url = index.php#contact" ); //wait for 5 seconds before redirecting
{
$result= "Thankyou, Ill be in touch shortly";
}
}
}
?>
我已经注释掉了一个 header 否则 $result
不会显示在联系表中。我怎样才能做到当用户发送消息而不是返回第一页时,它会重定向回 #contact
页面仍然显示 $result
并稍后刷新。
据我了解,您想在提交后立即转到#contact,五秒钟后页面将刷新并转到#contact?
在这种情况下,您可能需要在表单操作中添加#contact :
<form action="mypage.php#contact">
...
</form>
我试图让用户在刷新之前重定向回 #contact page
。但是,当单击发送消息时,网站会返回到第一页,我必须一直向下滚动到 #contact page
,然后 5 秒后它会刷新回第一页(这很好)。我的代码如下:
PHP
<?php
if($_POST['submit']){
if(!$_POST['name']){
$error= "<br/>-Please enter your name" ;
}
if(!$_POST['email']){
$error.= "<br/>-Please enter your email" ;
}
if (trim($_POST['message']) == "")
{
$error.= "<br/>-Please enter message";
}
if(!$_POST['contact']!=$match){
$error.= "<br/>-Please enter your contact number" ;
}
if ($error){
$result= "Whoops, error: $error";
}
else{
mail('mahdi.mashrafi@yahoo.com', "Contact message", "Name: ".$_POST['name']." Email: ".$_POST['email']."
Email: ".$_POST['name']."
Message : ".$_POST['message']."
Contact :".$_POST['contact'] );
// header("location:index.php#contact");
header( "refresh:5; url = index.php#contact" ); //wait for 5 seconds before redirecting
{
$result= "Thankyou, Ill be in touch shortly";
}
}
}
?>
我已经注释掉了一个 header 否则 $result
不会显示在联系表中。我怎样才能做到当用户发送消息而不是返回第一页时,它会重定向回 #contact
页面仍然显示 $result
并稍后刷新。
据我了解,您想在提交后立即转到#contact,五秒钟后页面将刷新并转到#contact?
在这种情况下,您可能需要在表单操作中添加#contact :
<form action="mypage.php#contact">
...
</form>