单击提交时,引导和PHP联系人表单将显示空白页
嗨,伙计们,我需要帮助 当我尝试测试我的引导表单时,它会显示一个白色屏幕。这是我的代码。NB我是网络开发新手,请原谅我的法语 这是我的index.html单击提交时,引导和PHP联系人表单将显示空白页,php,html,twitter-bootstrap,bootstrap-modal,Php,Html,Twitter Bootstrap,Bootstrap Modal,嗨,伙计们,我需要帮助 当我尝试测试我的引导表单时,它会显示一个白色屏幕。这是我的代码。NB我是网络开发新手,请原谅我的法语 这是我的index.html <html> <div class="container"> <div class="row"> <div class="col-md-6 col-md-offset-3" id="offer"> <h2 id="form"> LET'S WOR
<html>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3" id="offer">
<h2 id="form"> LET'S WORK ? </h2>
</div>
<div class="col-md-6 col-md-offset-3">
<form role="form" method="post" action="contact.php">
<div class="form-group">
<input type="text" class="form-control" placeholder="Enter Your Name">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
<div class="form-group">
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter Your Email">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
<div class="form-group">
<textarea class="form-control" id="textarea1" rows="3" placeholder="Enter Your Message here"> </textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
<div class="form-group">
<button type="submit" class="default-submit btn btn-large propClone bg-fast-pink btn-circle font-weight-300 text-white tz-text">SEND MESSAGE</button>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</form>
</div>
</div>
</div>
让我们工作吧?
点击页面上的提交后得到的屏幕截图,NB live not local有人吗
<?php
if (isset($_POST["submit"])) {
$error = [];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
/*$human = intval($_POST['human']); */
$from = 'Geofrey Zellah';
$to = 'hotbonge@gmail.com';
$subject = 'Message from Geofrey Zellah ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!isset($_POST['name']) || strlen($_POST['name']) === 0) {
$error['name'] = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$error['email'] = 'Please enter a valid email address';
}
//Check if message has been entered
if (!isset($_POST['message']) || strlen($_POST['name']) === 0) {
$error['message'] = 'Please enter your message';
}
/*
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
} */
// If there are no errors, send the email
if (empty($error)) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
index.php
<?php
if (isset($_POST["submit"])) {
$error = [];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
/*$human = intval($_POST['human']); */
$from = 'Geofrey Zellah';
$to = 'hotbonge@gmail.com';
$subject = 'Message from Geofrey Zellah ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!isset($_POST['name']) || strlen($_POST['name']) === 0) {
$error['name'] = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$error['email'] = 'Please enter a valid email address';
}
//Check if message has been entered
if (!isset($_POST['message']) || strlen($_POST['name']) === 0) {
$error['message'] = 'Please enter your message';
}
/*
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Your anti-spam is incorrect';
} */
// If there are no errors, send the email
if (empty($error)) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
index.php我得到了您想要实现的目标。您希望提交此表单,如果出现问题,您希望显示一些错误消息 您的情况是,当您提交表单时,它会被提交到
contact.php
。您的浏览器将显示您从contact.php
文件返回的内容。由于您的contact.php
不包含任何HTML内容,也不编写任何内容,所以返回的页面不包含任何内容
你有两个选择
第一条路:
echo
将错误消息发送到contact.php
文件。将以下内容添加到contact.php
文件的末尾
echo $result;
这样,当有人提交您的表单时。您将引导他进入一个新页面,该页面只有一行文字说明是错误还是成功
第二种方式
将该逻辑移动到index.html
。您必须将其重命名为index.php
。然后将表单设置为提交到同一页面
<form .... action="">
这将把表单提交到当前页面,即
index.php
。然后,将您的逻辑放入contact.php
索引顶部的index.php
我得到了您想要实现的目标。您希望提交此表单,如果出现问题,您希望显示一些错误消息
您的情况是,当您提交表单时,它会被提交到contact.php
。您的浏览器将显示您从contact.php
文件返回的内容。由于您的contact.php
不包含任何HTML内容,也不编写任何内容,所以返回的页面不包含任何内容
你有两个选择
第一条路:
echo
将错误消息发送到contact.php
文件。将以下内容添加到contact.php
文件的末尾
echo $result;
这样,当有人提交您的表单时。您将引导他进入一个新页面,该页面只有一行文字说明是错误还是成功
第二种方式
将该逻辑移动到index.html
。您必须将其重命名为index.php
。然后将表单设置为提交到同一页面
<form .... action="">
这将把表单提交到当前页面,即
index.php
。然后,将您的逻辑放在index.php
顶部的contact.php
中,您将看到许多由于没有名称属性而未定义的索引通知。@fred-li我没有收到任何错误,我只是在单击“提交”后出现白色屏幕,所以我不知道我的代码有什么问题thanks@Fred-ii-:我想,这个问题不是你上面提到的问题的翻版。(您标记的内容与此无关)并且您将看到许多由于没有名称属性而未定义的索引通知。@fred-li我没有收到任何错误,我只是在单击“提交”后出现白色屏幕,因此我不知道我的代码有什么问题thanks@Fred-ii-:我认为,这个问题不是你上面提到的问题的重复。(您标记的内容与此无关)您的意思是什么?你能解释一下你的答案吗?请看最新的答案非常感谢你,兄弟,事实上你的答案和imeesha一起解决了这个问题,现在完全符合我的要求,再次感谢你Yolo。你的传奇提交表单时,页面会重新加载。。。我不想那样。。。有没有办法让它不重新加载,仍然发送邮件?你是什么意思?你能解释一下你的答案吗?请看最新的答案非常感谢你,兄弟,事实上你的答案和imeesha一起解决了这个问题,现在完全符合我的要求,再次感谢你Yolo。你的传奇提交表单时,页面会重新加载。。。我不想那样。。。有没有办法让它不重新加载并仍然发送邮件
echo $result;
<form .... action="">