我正在使用 bootstrap,我想创建一个联系表单。我创建了一个名为 testForm.php 的文件,并在其中编写了我的 php 和 html 代码(我应该制作不同的文件吗?一个用于 php,一个用于 html?)。我的文件以 php 代码开头,在 html 代码之后。我一放<?php echo....
在 html 区域,无处不在,一直出现在网站 undefined index 中:. 例如
现在我只尝试使用一个参数 :thema 来查看它是否有效以及它是如何工作的,如果我对某些东西进行赋值,就会得到如上图所示的结果。 我的 PHP 代码:
<?php
if (isset($_POST["submit"])) {
$thema = $_POST['thema'];
// Check if thema has been entered
if (!$_POST['thema']) {
$errThema = 'Please enter your thema';
}
}
?>
和我的 html 代码:
<!-- MAIN SEITE -->
<h4><p class="text-primary"><u>Neuanforderungsformular</u></p></h4>
<!-- START FORM -->
<form method="post" role="form" action="testForm.php">
<!-- Thema Feld -->
<div class="form-group">
<label for="usr">Thema / Title:</label>
<input type="text" id="thema" name="thema" class="form-control input-lg" value="<?php echo htmlspecialchars($_POST['thema']); ?>">
</div>
<!-- Email Adresse Feld-->
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<div class="input-group col-sm-5">
<input type="text" class="form-control input-lg" placeholder="Ihre Email Addresse" aria-describedby="basic-addon2">
<span class="input-group-addon" id="basic-addon2">@teswt.de</span>
</div>
我怎样才能解决这个问题,这样我的联系表才能正常工作?
最佳答案
这样使用
$thema = isset($_POST['thema']) ? $_POST['thema'] : '';
代替
$thema = $_POST['thema'];
更新.1
尝试一下
<?php $thema = !empty($thema) ? $thema : ''; ?>
<input type="text" id="thema" name="thema" class="form-control input-lg" value="<?php echo htmlspecialchars($thema); ?>">
代替
<input type="text" id="thema" name="thema" class="form-control input-lg" value="<?php echo htmlspecialchars($_POST['thema']); ?>">
关于php - bootstrap php 联系表单值显示错误 <br/><b>通知</b> : Undefined variable: myThema in <b>C:\x\testForm. php</b> on line <b>105</b><br/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42970953/