注意:未定义的索引:在(路径)中提交
Notice: Undefined index: submit in (Path)
嘿 Whosebug 社区,我的联系表有问题。
我使用了这个PHP脚本:
<?php
if ($_POST["submit"]) {
$name = $_POST['name'];
$email = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Kontaktformular';
$to = 'email@mail.com';
$subject = 'Buchungsanfrage - $name';
$body ="From: $name\n: $phone\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Bitte geben Sie den Namen ein.';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Bitte geben Sie eine gültige E-Mail Adresse ein.';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Bitte hinterlassen Sie mir eine Nachricht.';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Ihre Anti-Span Antwort war falsch.';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Danke! Ich werde mich schnellstmöglich bei Ihnen melden.</div>';
} else {
$result='<div class="alert alert-danger">Entschuldigung, beim versenden Ihrer Nachricht ist etwas schief gelaufen. Bitte versuchen Sie es nochmal.</div>';
}
}
}
?>
还有这个 HTML 我的表格:
<div class="block block-primary-head no-pad">
<h3><i class="fa fa-pencil"></i> Buchungsanfrage</h3>
<div class="block-content">
<form role="form" method="post" action="fotografie.php">
<div class="form-group">
<label>Name*</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Vor- und Nachname" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
<div class="form-group">
<label>Telefonnummer</label>
<input type="text" class="form-control" id="phone" name="phone" placeholder="Ihre Telefonnummer" value="<?php echo htmlspecialchars($_POST['phone']); ?>">
</div>
<div class="form-group">
<label>E-Mail Adresse</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Ihre E-Mail Adresse" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
<div class="form-group">
<label>Nachricht</label>
<textarea class="form-control" id="message" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
<div class="form-group">
<label>2 + 3 = ?</label>
<input type="text" class="form-control" id="human" name="human" placeholder="Ihre Antwort">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<?php echo $result; ?>
</div>
<button type="submit" id="submit" name="submit" value="send" class="btn btn-primary">Absenden</button>
</form>
</div>
但是当我现在站在我这边的时候,我得到了以下错误:
注意:未定义索引:在第2行
的..\htdocs\projects\bootstrap-themes[=31=]1\contact\form-fotografie.php中提交
第 2 行代码如下:
if ($_POST["submit"]) {
可能是什么问题?
感谢您的帮助:-)
您似乎在尝试检查表单是否已提交。为此,您需要使用 isset
函数,如下所示
第 2 行:
if ($_POST["submit"]) {
应阅读:
if (isset($_POST["submit"])) {
编辑:
您应该始终在使用之前检查变量是否已设置,以便更正您的 html 您需要更改以下内容:
<div class="form-group">
<label>E-Mail Adresse</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Ihre E-Mail Adresse" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
收件人:
<div class="form-group">
<label>E-Mail Adresse</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Ihre E-Mail Adresse" value="<?php if(isset($_POST['email'])) { echo htmlspecialchars($_POST['email']); } ?>">
<?php if(isset($errEmail) && ($errEmail) != "") { echo "<p class='text-danger'>$errEmail</p>"; } ?>
</div>
您需要对所有具有相关变量名称的表单组进行此更改,让我知道您的进展情况
嘿 Whosebug 社区,我的联系表有问题。
我使用了这个PHP脚本:
<?php
if ($_POST["submit"]) {
$name = $_POST['name'];
$email = $_POST['phone'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']);
$from = 'Kontaktformular';
$to = 'email@mail.com';
$subject = 'Buchungsanfrage - $name';
$body ="From: $name\n: $phone\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Bitte geben Sie den Namen ein.';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Bitte geben Sie eine gültige E-Mail Adresse ein.';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Bitte hinterlassen Sie mir eine Nachricht.';
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = 'Ihre Anti-Span Antwort war falsch.';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Danke! Ich werde mich schnellstmöglich bei Ihnen melden.</div>';
} else {
$result='<div class="alert alert-danger">Entschuldigung, beim versenden Ihrer Nachricht ist etwas schief gelaufen. Bitte versuchen Sie es nochmal.</div>';
}
}
}
?>
还有这个 HTML 我的表格:
<div class="block block-primary-head no-pad">
<h3><i class="fa fa-pencil"></i> Buchungsanfrage</h3>
<div class="block-content">
<form role="form" method="post" action="fotografie.php">
<div class="form-group">
<label>Name*</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Vor- und Nachname" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
<div class="form-group">
<label>Telefonnummer</label>
<input type="text" class="form-control" id="phone" name="phone" placeholder="Ihre Telefonnummer" value="<?php echo htmlspecialchars($_POST['phone']); ?>">
</div>
<div class="form-group">
<label>E-Mail Adresse</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Ihre E-Mail Adresse" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
<div class="form-group">
<label>Nachricht</label>
<textarea class="form-control" id="message" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
<div class="form-group">
<label>2 + 3 = ?</label>
<input type="text" class="form-control" id="human" name="human" placeholder="Ihre Antwort">
<?php echo "<p class='text-danger'>$errHuman</p>";?>
</div>
</div>
<div class="form-group">
<?php echo $result; ?>
</div>
<button type="submit" id="submit" name="submit" value="send" class="btn btn-primary">Absenden</button>
</form>
</div>
但是当我现在站在我这边的时候,我得到了以下错误:
注意:未定义索引:在第2行
的..\htdocs\projects\bootstrap-themes[=31=]1\contact\form-fotografie.php中提交第 2 行代码如下:
if ($_POST["submit"]) {
可能是什么问题?
感谢您的帮助:-)
您似乎在尝试检查表单是否已提交。为此,您需要使用 isset
函数,如下所示
第 2 行:
if ($_POST["submit"]) {
应阅读:
if (isset($_POST["submit"])) {
编辑:
您应该始终在使用之前检查变量是否已设置,以便更正您的 html 您需要更改以下内容:
<div class="form-group">
<label>E-Mail Adresse</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Ihre E-Mail Adresse" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
收件人:
<div class="form-group">
<label>E-Mail Adresse</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Ihre E-Mail Adresse" value="<?php if(isset($_POST['email'])) { echo htmlspecialchars($_POST['email']); } ?>">
<?php if(isset($errEmail) && ($errEmail) != "") { echo "<p class='text-danger'>$errEmail</p>"; } ?>
</div>
您需要对所有具有相关变量名称的表单组进行此更改,让我知道您的进展情况