php - bootstrap php 联系表单值显示错误 <br/><b>通知</b> : Undefined variable: myThema in <b>C:\x\testForm. php</b> on line <b>105</b><br/>

标签 php html twitter-bootstrap contact-form

我正在使用 bootstrap,我想创建一个联系表单。我创建了一个名为 testForm.php 的文件,并在其中编写了我的 php 和 html 代码(我应该制作不同的文件吗?一个用于 php,一个用于 html?)。我的文件以 php 代码开头,在 html 代码之后。我一放<?php echo....在 html 区域,无处不在,一直出现在网站 undefined index 中:. 例如 enter image description here

现在我只尝试使用一个参数 :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/

相关文章:

javascript - 在 fullcalendar v4 中编辑和删除事件

php - 为什么 PHP session_destroy() 不起作用?

php - 上传时在数据库中插入文件名而不是 CakePHP 中的数组

javascript - 在 flickr 上将 CSS 选择器与 beautifulsoup 一起使用时遇到困难,我做错了什么吗?

php - 如果索引小于某个值,则打印所有数组字符串

html - CSS:具有边距和对齐方式的响应式 Div?

java - 避免使用 Java 编写 HTML

javascript - 当尝试在 JS 中单击时更改 V 形方向时,只有 1 个 V 形发生变化。

javascript - 通过单击外部关闭 Bootstrap 弹出窗口

javascript - Bootstrap Carousel 前进时跳转到页面顶部