duanlao6573 2015-07-19 15:44
浏览 45
已采纳

提交后隐藏电子邮件表单

I have a PHP email form embedded at the top of the HTML of my contact form page (index.php):

<?php
    if (isset($_POST["submit"])) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'Camino Contact Form'; 
        $to = 'email@example.com'; 
        $subject = 'Message Contact Form ';     
        $body ="From: $name
 E-Mail: $email
 Message:
 $message";

if (!$errName && !$errEmail && !$errMessage) {
    if (mail ($to, $subject, $body, $from)) {
        $result='<div>Thank You! I will be in touch</div>';
    } else {
        $result='<div>Sorry there was an error sending your message.</div>';
    }
}
    }
?>

HTML:

<form role="form" method="post" action="index.php">
    ...
</form>

and I wanted to hide the form only after successful submission. How can I do this?

  • 写回答

2条回答 默认 最新

  • dsaf415212 2015-07-19 16:05
    关注

    In your CSS file;

    .hide {
        display:none;
    }
    

    (If unsure how to do this, this question should help)

    Then inside your PHP if block;

    $class = "";
    if (mail ($to, $subject, $body, $from)) {
            $result='<div>Thank You! I will be in touch</div>';
            $class = 'class="hide"';
        } else {
            $result='<div>Sorry there was an error sending your message.</div>';
        }
    

    and finally, on index.php:

    <form role="form" method="post" action="index.php" <?php echo $class ?>>
    

    Now you can hide the entire form, with a little bit of CSS and a dynamic variable.

    Edit:

    If you wanted to avoid using an external or internal CSS file entirely, you could apply the CSS inline to your html element directly, like so;

    $style = 'style = "display:none;"';
    

    An alternative approach, if you're not using style sheets or any other CSS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献