doukuang6795 2013-01-03 23:23
浏览 33

表单提交后刷新包含不同内容的页面

I want to have a php contact form, that when submitted (if no errors), will refresh the same page, and remove the contact form, and replace it with some text e.g. "thank you for contacting us". Is there a best way to do this?

  • 写回答

2条回答 默认 最新

  • doukuizuo1795 2013-01-03 23:26
    关注

    You could always do something like this:

    <?php
        $posted = false;
        if( isset($_POST['submit']) ) {
            /* Process $_POST */
    
            /* Do your things */
    
            /* Set a variable hinting if a post has been done */ 
            $posted = true;
        }
    ?>
    <!DOCTYPE html>
    <html>
        <body>
        <?php if( $posted ): ?>
            <form method="post">
                <input name="foo" />
                <input name="bar" />
                <input name="car" />
                <input name="submit" type="submit" value="Submit" />
            </form>
        <?php else: ?>
            <h1>Thank you for contacting us!</h1>
        <?php endif; ?>
        </body>
    </html>
    
    评论

报告相同问题?