drutjkpsr67393592 2017-04-13 13:15
浏览 39
已采纳

用php在不同的页面上显示div

I want my contact form to change to 'mail successful' when a mail has been send. So the div from the contactform has to be display:none and the div from 'mail successful' has to be display:block right?

Somehow I don't succeed in this.

Here is a print screen and how I want it: How I want that it gets chanced

This is the php code I use (only the end cause that's the only needed part):

$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

if ($success) {
    ?>
    <style type="text/css">
        #mail_succeed {
            display: block;
        }
        #mail_failed {
            display: none;
        }
        #contat-area{
            display: none;
        }
    </style>
    <?php
    header('Location: index.php#contact');
    exit();
} else {
    ?>
    <style type="text/css">
        #mail_failed {
            display: block;
        }
        #mail_succeed {
            display: none;
        }
        #contact-area{
            display: none;
        }
    </style>
    <?php
    header('Location: index.php#contact');
    exit();
}
?>

This is the html code I have now (its quit a bit of code, I also added the modal because maybe its important):

<div id="myModal" class="modal">
         <div class="modal-content">
                <div class="modal-header">
                    <span class="close">x</span>
                    <h4>Contact Form</h4>
                </div>
                <div class="modal-body">
                    <div id="contact-area">
                        <form method="post" action="contactengine.php">
                            <div class="nametel">
                                <div class="name">
                                    <label for="Name">Name:</label>
                                    <input type="text" name="Name" id="Name">
                                </div>
                                <div class="tel">
                                    <label for="Tel">Tel:</label>
                                    <input type="text" name="Tel" id="Tel">
                                </div>
                            </div>

                            <label for="Email">Email:</label>
                            <input type="text" name="Email" id="Email">

                            <label for="Message">Message:</label><br>
                            <textarea name="Message" rows="20" cols="20" id="Message"></textarea>
                            <input type="submit" name="submit" value="Send" class="submit-button" onclick="showDiv()">
                        </form>
                        <div style="clear: both;"></div>
                    </div>
                    <div id="mail_succeed" style="display: none">
                        <h3>Mail succesfull send, go back to </h3>
                        <span class="close"><a href="index.php#contact">contact page</a></span>
                    </div>
                    <div id="mail_failed" style="display: none">
                        <h3>Mail not send, go back to </h3>
                        <span class="close"><a href="index.php#contact">contact page</a></span>
                    </div>
                </div>
                <div class="modal-footer"></div>
            </div>
        </div>

I possibly send to much code but i'm not sure what to leave away since it can be important.

  • 写回答

1条回答 默认 最新

  • dsjz1119 2017-04-13 13:32
    关注

    If you don't want to use jQuery/Ajax then you can do the following :

    In contactengine.php, change your header redirects to:

    header('Location: index.php?resp=1#contact');

    and

    header('Location: index.php?resp=0#contact');

    respectively for success and failure.

    Then on index.php add this little php code in your head section (or wherever you define styles):

    if(isset($_GET['resp']) && $_GET['resp']==1){
         echo '
           <script type="text/javascript">$("#ButtonThatOpensModal").click();</script>
           <style type="text/css">
            #mail_succeed {
                display: block;
            }
            #mail_failed {
                display: none;
            }
            #contat-area{
                display: none;
            }
        </style>';
    }
    elseif(isset($_GET['resp']) && $_GET['resp']==0){
         echo '<style type="text/css">
            #mail_failed {
                display: block;
            }
            #mail_succeed {
                display: none;
            }
            #contact-area{
                display: none;
            }
        </style>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器