douqian9729 2019-01-15 19:27
浏览 52
已采纳

如何避免OnePager网站上的页面刷新上的数据重新提交+避免浏览器弹出窗口

i already searched a lot but none of these solutions can help me. I want to avoid Data Re-Submit on Page Refresh on a Onepager Site. I don´t got any other page to redirect. + Avoid Browser PopUp

I am a total beginner so sorry for the "terrible code".

<?php
$errors = array();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $issend = true;
    if (isset($_POST['name'])) {
        $name = $_POST['name'];
    }

    if (isset($_POST['phonenumber'])) {
        $phonenumber = $_POST['phonenumber'];
    }

    if ($phonenumber === null || mb_strlen($phonenumber) === 0) {
        $errors[] = 'phonenumber.empty';
    }

    if ($name === null || mb_strlen($name) === 0) {
        $errors[] = 'name.empty';
    }


    if (empty($errors)) {
        mail('email@email.com', 'Contact Form', 'Name: '.$_POST["name"] . '
 Telefonnummer:' .$_POST["phonenumber"]);
        $_POST['name'] = '' ;
        $_POST['phonenumber'] = '' ;
        $_POST = null;
    }

}
  • 写回答

1条回答 默认 最新

  • drm16022 2019-01-15 19:31
    关注

    on a successful submission, redirect the user to a success page. If you don't have one, just create a simple HTML/PHP page

    success.php

    <?php
        echo "Successful submission";
    ?>
    

    Your page with the form add this to bottom of your check

    if (empty($errors)) {
            mail('email@email.com', 'Contact Form', 'Name: '.$_POST["name"] . '
     
            Telefonnummer:' .$_POST["phonenumber"]);
            $_POST['name'] = '' ;
            $_POST['phonenumber'] = '' ;
            $_POST = null;
    
            header('Location: http://www.domainname.com/success.php');
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波