Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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/1/php/279.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/7/neo4j/3.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 显示php页面的隐藏部分_Javascript_Php - Fatal编程技术网

Javascript 显示php页面的隐藏部分

Javascript 显示php页面的隐藏部分,javascript,php,Javascript,Php,我有一个php页面。在底部有一个联系方式。我想做的是在邮件发送时隐藏联系人表单,而是显示感谢部分。这意味着当客户第一次来到页面时,表单就会显示出来。提交后,感谢部分出现 我看过,但不知道是怎么做的 我有一个想法,当页面加载时,它必须检查一个变量以查看邮件是否已发送,但这可能是错误的。当我需要这样的内容时,我通常将提交按钮命名为“提交”,并检查它是否已设置 <input type="submit" name="submit" value="Send form"> 当我做类似的事情时,

我有一个php页面。在底部有一个联系方式。我想做的是在邮件发送时隐藏联系人表单,而是显示感谢部分。这意味着当客户第一次来到页面时,表单就会显示出来。提交后,感谢部分出现

我看过,但不知道是怎么做的


我有一个想法,当页面加载时,它必须检查一个变量以查看邮件是否已发送,但这可能是错误的。

当我需要这样的内容时,我通常将提交按钮命名为“提交”,并检查它是否已设置

<input type="submit" name="submit" value="Send form">

当我做类似的事情时,我倾向于在表单中添加一个按钮并给它命名

<button type="submit" id="submit" name="submit">Submit</button>
提交
然后在我的PHP中检查表单是否已提交

<?php
if(isset($_POST['submit'])) {
  // Actions After Submit
}
else
{
 // Load The Form
}
?>

它相当简单;添加
退出(“消息…”)
mail()之后

邮件(…)
所在的PHP中,您可以执行以下操作:

mail($to,$subject,$message,$headers);
    exit("Thank you, your message has been sent. <a href='home.php'>Click here</a> to return to our Website.");
mail($to、$subject、$message、$headers);
退出(“谢谢,您的信息已发送。请返回我们的网站。”);
这里是一个使用纯PHP的完整的基本解决方案,因为没有提供任何代码

以下内容将作为同一文件中的所有内容运行

<?php

   if(isset($_POST['send'])) {
   // Prepare the email
   $to = 'email@example.com';

$mail_from = $_POST['email'];
   $subject = 'Message sent from website';
   $message = $_POST['message'];

$name = $_POST['name'];
$header = "From: $name <$mail_from>";

   // Send it
   $sent = mail($to, $subject, $message, $header);
   if($sent) {

    exit("Thank you, your message has been sent. <a href='home.php'>Click here</a> to return to our Website.");

   } else {
   echo 'Sorry, your message could not be sent. The error has been logged.';
   }
   } // closing brace for if(isset($_POST['send']))
?>

<form method="post" action="">
    <p>
        <label for="name">Name</label>
        <input type="text" id="name" name="name" />
    </p>
    <p>
        <label for="email">Email</label>
        <input type="text" id="email" name="email" />
    </p>
    <p>
        <label for="message">Message</label>
        <textarea id="message" name="message" rows="6" cols="30"></textarea>
    </p>
    <p>
        <input type="submit" name="send" value="Send message" />
    </p>
</form>


名称

电子邮件

消息


非常简单,如果不这样,下面是示例表单

<?php
if(isset($_POST['submit'])) { ?>
//write your other actions on form data
<h2>THANK YOU</h2>
<?php
} else { ?>
<form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label><h4>Username:</label>
<input type="text" name="username">
<input type="submit" name="submit" value="submit"/>
</form>
<?php }
?>

//在表单数据上编写其他操作
非常感谢。

您需要做一些关于PHP的入门教程。您所描述的是通过条件输出实现的,即if/else。去尝试一些东西,然后回来,并张贴一些代码,如果你卡住了。
<?php
if(isset($_POST['submit'])) { ?>
//write your other actions on form data
<h2>THANK YOU</h2>
<?php
} else { ?>
<form name="login" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label><h4>Username:</label>
<input type="text" name="username">
<input type="submit" name="submit" value="submit"/>
</form>
<?php }
?>