好的,我在index.php上有一个电子邮件表单。我正在使用mail_check.php来验证两个字段是否都已填写。(还有更多正在验证的内容,但不包括在内,因为这不是问题)
主要问题是,我想从mail_check.php将一条消息发送回index.php ,并在div id="mailrespond"中放置一条消息。我选择了 PHP 和 Javascript 来实现这一点。
索引.php
<div id="mailrespond"></div>
<form method="post" action="mail_check.php">
<span>Name: <input type="text" name="name" maxlength="30" /></span><br />
<span>Email: <input type="text" name="email" maxlength="30" /></span><br />
<input type="submit" value="Sign Up" name="registration">
</form>
</div>
mail_check.php
if(isset($_POST['registration']))
$name = $_POST['name'];
$email = $_POST['email'];
if(empty($email) || empty($name)){
// if email and name are empty
//header ("location: index.php");
?>
<script language="javascript" type="text/javascript">
window.location.replace("index.php");
function msg() {
// creating elements are a safer method then innerHTML
dv = document.createElement('div'); // creates a Div element
dv.setAttribute('class', 'error_msg'); // adds error styling
txt = document.createTextNode('please enter your name and email '); // create the message
dv.appendChild(txt); // place the text node on the element
document.getElementById("mailrespond").appendChild(dv);
}
window.onload = msg;
</script>
<?php }
代码继续,但我的问题是我没有收到反馈消息。我对这一切有点陌生-如果您能提供帮助,将不胜感激!:)