douqian9729
douqian9729
2019-01-15 19:27

如何避免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 drm16022 2年前

    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');
        }
    
    点赞 评论 复制链接分享