私はこの小さなJavaScriptを使用して、電子メールが有効かどうかを確認します。クライアント側を確認し、メールが有効であることは100%重要ではないため、確認のためだけにユーザーをリダイレクトしたくありません。
問題は、ポップアップが表示されても、ユーザーの値が挿入されたままになることです。
<script>
function popup()
{
var email = document.getElementById("email").value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (document.getElementById("email").value == "") {
alert("Enter an email");
return false;
}
else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length) {
alert("The email is not valid");
return false;
}
else
window.location = "email.php";
return true;
}
</script>
これがHTMLフォームです
<form action="email.php" accept-charset="UTF-8" class="signup_form" id="signup_form" method="post">
<input class="txt accent-color colorize_border-color required" id="email" name="email" placeholder="Indtast E-mail her" data-label-text="Email" type="email">
<input class="submit button big btn" id="submit_button" name="submit" value="Deltag nu!" onclick="return popup()" type="submit">
</form>
「typesubmit」を削除しても機能しますが、次のページの$ _POSTで値を取得できません。これらは、nullです。
これを回避する方法はありますか?