我有一个功能齐全的联系表格,并显示一个"谢谢你"提交时的消息。唯一的问题是感谢消息显示在表单上方,因此当用户单击消息时,消息是不明显的。
我的表格在这里:
http://impressify.co/business-writing.php
如何制作它以便当我单击提交按钮时页面滚动到顶部然后显示联系人消息?我不想让用户明白邮件已成功发送。
我的代码如下:
<?
if($_SERVER['REQUEST_METHOD'] == "POST") {
$allowedExts = array("gif", "jpeg", "jpg", "png", "doc", "pdf", "docx",
"jpg", "docx", "odt", "txt", "msg", "csv", "pps", "ppt", "pptx", "xml",
"tar", "m4a", "mp3", "wav", "wma", "mp4", "mov", "flv", "exe");
for ($i = 1; $i <= 2; $i++) {
$temp = explode(".", $_FILES["attach".$i]["name"]);
$extension = end($temp);
if (in_array($extension, $allowedExts)) {
move_uploaded_file($_FILES["attach".$i]["tmp_name"],
"upload/" .$_POST["firstname"]."-".$_FILES["attach".$i]["name"]);
}
}
$to = 'myemail@gmail.com';
$subject = 'Business Writing Request from
'.$_POST["firstname"].$_POST["email"];
$message = $_POST["message"]."\n\n\n Attachments: ".$_FILES["attach1"]
["firstname"]." ".$_FILES["attach2"]["firstname"]."
".$_FILES["attach3"]["firstname"];
$firstname=$_REQUEST['firstname'];
$companyname=$_REQUEST['companyname'];
$email=$_REQUEST['email'];
if (($firstname=="")||($email=="")||($message==""))
{
echo "<strong><p class =greentip>A first name, message, and email are
required, please fill <a href=/business-writing.php>the form</a>
again.</p></strong><br>";
}
else{
mail("n.dumanov@gmail.com", $subject, $message, $email);
echo "<strong><p>Your free consultation request has been received!
Expect a detailed response within the next 24 hours!</p></strong>";
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="row uniform 50%">
<div class="6u 12u(mobilep)">
<input name="firstname" type="text" value="" placeholder="Name"><br>
</div>
<div class="6u 12u(mobilep)">
<input name="companyname" type="text" value="" placeholder="Company Name"><br>
</div>
<div>
<input name="email" type="text" value="" placeholder="Email"><br>
</div>
</div>
<div class="row uniform 50%">
<div class="12u">
<textarea name="message" rows="7" cols="30" placeholder="Give us a general sense of the kind of writing you or your ogranization needs."></textarea><br>
</div>
</div>
<br><br>
<center><input class type="submit" value="submit"></center> <br>
</form>
答案 0 :(得分:1)
为什么不设置表单的ID,然后直接指向表单操作中的锚点:
<form action="#my-form" method="post" enctype="multipart/form-data" id="my-form">
这将基本上提交您的表单并重新加载您的网址:
http://impressify.co/business-writing.php#my-form
它应该把你带到你想要的地方,它在我设置的简单测试中工作。
或者我认为您可以将包含确认消息的"my-form"
标记的ID设置为<p>
,而不是将表单的ID设置为"form-confirmation-message"
,并设置表单对action="#form-confirmation-message"
这可能是最好的选择,因为它会使您正确接收邮件,而不是表单,这就是您的信息。