我在测试服务器上有我的主页。当我提交表单时,页面显示一个空白页面,但它也在发送电子邮件。
第二个问题是,复选框值没有显示在电子邮件中,我不认为它们是由php文件读取的......
我的按钮有正确的类型(提交),我的姓名中没有任何拼写错误...我不是那么喜欢php,因此我真的不知道,出了什么问题。任何帮助将不胜感激。
HTML的代码
<form action="contact.php" id="form" method="post" name="send">
<span class="input input--kuro">
<div class="row">
<h3 class="big-blue">Kontaktformular</h3>
<h2 class="small-grey">Bitte füllen Sie das Formular aus, damit wir Ihnen ein individuelles Angebot zukommen lassen können.</h2>
</div>
<div class="row">
<div class="row">
<div class="input-wrapper col-md-4 col-centered">
<input class="requiredField name subscribe-requiredField input__field input__field--kuro" type="text" name="name" placeholder="Name" id="name">
<label class="input__label input__label--kuro" for="subscribe-email">
<span class="mail input__label-content input__label-content--kuro">Name</span>
</label>
</div>
<div class="input-wrapper col-md-4 col-centered">
<input class="requiredField subscribe-requiredField input__field input__field--kuro" type="text" name="firma" placeholder="Firma" id="firma">
<label class="input__label input__label--kuro" for="subscribe-email">
<span class="mail input__label-content input__label-content--kuro">Firma</span>
</label>
</div>
</div>
<div class="row">
<div class="input-wrapper col-md-4 col-centered">
<input class="requiredField email subscribe-requiredField input__field input__field--kuro" type="text" name="email" placeholder="Email" id="email">
<label class="input__label input__label--kuro" for="subscribe-email">
<span class="mail input__label-content input__label-content--kuro">Email</span>
</label>
</div>
<div class="input-wrapper col-md-4 col-centered">
<input class="requiredField subscribe-requiredField input__field input__field--kuro" type="text" name="number" placeholder="Telefonnummer" id="number">
<label class="input__label input__label--kuro" for="subscribe-email">
<span class="mail input__label-content input__label-content--kuro">Telefonnummer</span>
</label>
</div>
</div>
</div>
</div>
</ul>
<li><button class="submit-button" id="submit" type="submit">Senden</button></li>
<li><button type="button" class="btn btn-primary added-btn" title="Zur Übersicht." id="gesamt-zurueck" name="submit-clear" >Zurück zur Übersicht</button></li>
</ul>
</div>
</span>
<div class="hidden">
<ul class="checker-wrap">
<li><input type="checkbox" id="0" value="Zielgruppendefinition" class="0 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="1" value="Namensfindung & Logoentwicklung" class="1 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="2" value="Exposé" class="2 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="3" value="Textdesign" class="3 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="4" value="Anzeigenkampagnen" class="4 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="5" value="Außenwerbung" class="5 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="6" value="Bautafelgestaltung" class="6 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="8" value="Website" class="8 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="9" value="Social Media" class="9 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="10" value="Digitale Präsentation" class="10 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="11" value="Innenvisualisierungen" class="11 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="14" value="Außenvisualisierungen" class="11 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="12" value="Virtuelle Begehung" class="12 checker" name="checkbox-group[]"></li>
<li><input type="checkbox" id="13" value="Augmented Reality" class="13 checker" name="checkbox-group[]"></li>
</ul>
</div>
PHP文件代码:
<?php
$errors = '';
$myemail = 'schroeder@exposedesign.de';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['number']) ||
empty($_POST['firma']))
{
$errors .= "\n Error: Required Field";
}
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$firma = $_POST['firma'];
$checkbox = $_POST['checkbox-group'];
if (!eregi(
"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
$email))
{
$errors .= "\n Error: Invalid Email Address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Angebot angefordert";
$email_body = "\n Name: $name \n Email: $email \n Firma: $firma \n Telefon: \n $number";
$headers = "From: $email";
$leistungen = "\n Gewählte Leistungen: $checkbox";
mail($to, $email_subject, $email_body, $headers, $leistungen);
}
?>
jQuery代码:
// contact form
$("form#form").submit(function() {
$("form#form .error").remove();
var s = !1;
if ($(".requiredField").each(function() {
if ("" === jQuery.trim($(this).val())) {
$(this).prev("label").text(), $(this).parent().append('<span class="error">This field is required</span>'), $(this).addClass(
"inputError"), s = !0;
}
else if ($(this).hasClass("email")) {
var r = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
r.test(jQuery.trim($(this).val())) || ($(this).prev("label").text(), $(this).parent().append('<span class="error">Invalid email address</span>'), $(
this).addClass("inputError"), s = !0);
}
}), !s) {
$("form#form input.submit").fadeOut("normal", function() {
$(this).parent().append("");
});
var r = $(this).serialize();
$.post($(this).attr("action"), r, function() {
$("form#form").slideUp("fast", function() {
$(this).before('<div class="success">Your email was sent successfully.</div>');
$(".done-wrapper").toggleClass("hidden");
});
});
}
$('.label-wrap ul').find('.'+btn_class[0]).toggleClass("hide-me added haken");
$('#form')[0].reset();
return !1;
});
答案 0 :(得分:1)
关于空白页问题: 你只是处理,而不是输出任何东西。你可以简单地在最后发布一个redirect-header - 可能是根据发生的错误而发生的。
// 307 Temporary Redirect
header("Location: /foo.php",TRUE,307);
..或者只是在处理后输出内容。一个好的做法可能是将处理和表单显示保存在一个文件中 - 然后您可以使用不产生错误的字段预填充表单,并标记失败的字段,以便用户可以再次尝试。
关于复选框组问题:
echo implode( ", ", $_POST['checkbox-group'] );
向自己证明你实际上已经传递了一些东西:
header("Content-type:text/plain;charset=utf-8");
echo print_r($_POST,TRUE);