联系感谢页面
Contact thank you page
目前,我的联系表单在提交时会转到另一个页面,并带有一条警告,上面写着感谢您与我们联系,但是,我想要它做的是在屏幕上的任何地方以弹出窗口或文本的形式说谢谢您与我们联系说声谢谢,但与联系表在同一页面上
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = ' dsaas@asadsd.asdasd';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
<form action="contact.php" style="height:auto;" class="form" method="post">
<h1>Your name</h1>
<input type="text" class="form textbox" name="cf_name"><br>
<h1>Your e-mail</h1>
<input type="text" class="form textbox" name="cf_email"><br>
<h1>Message</h1>
<textarea class="form textbox" name="cf_message"></textarea><br>
<input type="submit" value="Send">
我尝试将 if 语句替换为
if ($mail_status) { ?>
<div><h1>thank you for submitting the contcat form</h1> </div>
<?php
}
但这还是转到了另一页
您需要在发送前验证您的数据。
if(isset($_POST['submit']){
$field_name = isset($_POST['cf_name'])? $_POST['cf_name']:'';
$field_email = isset($_POST['cf_email'])? $_POST['cf_email']:'';
$field_message = isset($_POST['cf_message'])? $_POST['cf_message']:'';
if(empty($field_name){
$error = 'Field Name is blank';
}elseif(empty($field_email) || filter_var($field_email, FILTER_VALIDATE_EMAIL)){
$error = 'Email is invalid';
}elseif(empty($field_message)){
$error = 'Message is blank';
}else{
$mail_to = ' dsaas@asadsd.asdasd';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if($mail_status){ ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
document.getElementById("myForm").reset();//reset the form
</script>
<?php }else{ ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
//document.getElementById("myForm").reset();//Reset the form
</script>
<?php }
}
}
既然你不想去另一个,你可以在同一页面中post通过指定如下操作或者你不一定需要这样做。
<form action="<?php echo $_SERVER['PHP_SELF'];?>"
style="height:auto;" class="form" id="myForm" method="post">
<h1>Your name</h1>
<input type="text" class="form textbox" name="cf_name"><br>
<h1>Your e-mail</h1>
<input type="text" class="form textbox" name="cf_email"><br>
<h1>Message</h1>
<textarea class="form textbox" name="cf_message"></textarea><br>
<input type="submit" value="Send">
<div class="error">
<?php if(!empty($error)){ echo $error; } ?>
</div>
希望这可能有所帮助。
目前,我的联系表单在提交时会转到另一个页面,并带有一条警告,上面写着感谢您与我们联系,但是,我想要它做的是在屏幕上的任何地方以弹出窗口或文本的形式说谢谢您与我们联系说声谢谢,但与联系表在同一页面上
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = ' dsaas@asadsd.asdasd';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact_page.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
window.location = 'contact_page.html';
</script>
<?php
}
?>
<form action="contact.php" style="height:auto;" class="form" method="post">
<h1>Your name</h1>
<input type="text" class="form textbox" name="cf_name"><br>
<h1>Your e-mail</h1>
<input type="text" class="form textbox" name="cf_email"><br>
<h1>Message</h1>
<textarea class="form textbox" name="cf_message"></textarea><br>
<input type="submit" value="Send">
我尝试将 if 语句替换为
if ($mail_status) { ?>
<div><h1>thank you for submitting the contcat form</h1> </div>
<?php
}
但这还是转到了另一页
您需要在发送前验证您的数据。
if(isset($_POST['submit']){
$field_name = isset($_POST['cf_name'])? $_POST['cf_name']:'';
$field_email = isset($_POST['cf_email'])? $_POST['cf_email']:'';
$field_message = isset($_POST['cf_message'])? $_POST['cf_message']:'';
if(empty($field_name){
$error = 'Field Name is blank';
}elseif(empty($field_email) || filter_var($field_email, FILTER_VALIDATE_EMAIL)){
$error = 'Email is invalid';
}elseif(empty($field_message)){
$error = 'Message is blank';
}else{
$mail_to = ' dsaas@asadsd.asdasd';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if($mail_status){ ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
document.getElementById("myForm").reset();//reset the form
</script>
<?php }else{ ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to gordon@template-help.com');
//document.getElementById("myForm").reset();//Reset the form
</script>
<?php }
}
}
既然你不想去另一个,你可以在同一页面中post通过指定如下操作或者你不一定需要这样做。
<form action="<?php echo $_SERVER['PHP_SELF'];?>"
style="height:auto;" class="form" id="myForm" method="post">
<h1>Your name</h1>
<input type="text" class="form textbox" name="cf_name"><br>
<h1>Your e-mail</h1>
<input type="text" class="form textbox" name="cf_email"><br>
<h1>Message</h1>
<textarea class="form textbox" name="cf_message"></textarea><br>
<input type="submit" value="Send">
<div class="error">
<?php if(!empty($error)){ echo $error; } ?>
</div>
希望这可能有所帮助。