来自 php GET 的明确消息

clear message that came from php GET

本文关键字:消息 php GET 来自      更新时间:2023-09-26

让我澄清一下。

我有一个 HTML 表单,用于在名为 contact.php 的文件中发送电子邮件

在服务器端,我在发送电子邮件后在 php 中有这个

header('Location:contact.php?co=1'); exit();

在客户端(在包含表单的同一文件中(

if ($_GET['co']) {
    echo 'We got it!';          
    }

因此,用户知道邮件是否已发送。

我怎样才能清除该消息,即"我们明白了"?

我想做一些类似的东西

<input name="mail" type="email"  onFocus="cleatThemessage" ><br>

因此,当用户单击表单中的字段时,消息会消失。

谢谢

header('Location:contact.php?co=1'); exit();之前

$_SESSION['notification'] = "We got it";

和改变,

if ($_GET['co']) {
    if(isset($_SESSION['notification']) && $_SESSION['notification'] != '') {
        echo $_SESSION['notification'];
        unset($_SESSION['notification']);
    }          
}

为此,我假设您的表单提交到一个页面,例如 saveContact.php插入数据库查询后,您将其重定向到 contact.php?co=1,这样$_SESSION['notification'] = 'We got it'在插入数据库查询后仅执行一次。

这可能

对你有用:

<?php
    if ($_GET['co']) {
        echo '<div id="message">We got it!</div>';          
    }
?>
<input name="mail" type="email"  onFocus="document.getElementById('message').innerHTML = '' ;" ><br>

像这样:

Html

<input name="mail" type="email"  onFocus="clearThemessage(this)" ><br>

爪哇语

function clearTheMessage(element) {
   element.value = "";
}
<?php
if(isset($_GET['co'])){
    echo '<p id="gotit">We got it!</p>';
}?>
<input name="mail" type="email"  onFocus="removeMessage()" >
<script type="text/javascript">
function removeMessage(){
    var el = document.getElementById('gotit');
    if(typeof(el) != 'undefined' && el != null){
        el.remove();
    }
}
</script>