文本区域未在表单中发布值

Textarea not posting value in form

我找到了很多关于类似问题的解决方案,但不幸的是 none 解决了我的问题。除文本区域外,该表单工作正常。表单没有 post textarea 值,它显示

undefined index: description

这是 html 代码:

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post"> 
 <div class="form-group">
                    <label>Description</label>
                    <textarea name="description" rows="4" cols="50" class="form-control" value=""></textarea>
 </div>
</form>

php

$description = $_POST['description'];

有谁知道问题出在哪里?提前致谢。

始终确保在使用 isset 函数访问表单字段的值之前测试提交 button 是否已被单击。这是因为当服务器加载页面时,服务器会尝试检索尚未输入的输入字段的值。因此 undefined。另一种解决方案是使用另一个页面来处理您的表单提交。

    <?php
    if(isset($_POST['submit'])){
     $age = $_POST['age'];
     $description = $_POST['description'];
    }
    ?>
      <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
        <div class="form-group">
          <input name="age" />
          <label>Description</label>
          <textarea name="description" rows="4" cols="50" class="form-control" value=""></textarea>
          <button name="submit" value="save">Save</button>
        </div>
      </form>