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

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


未定义索引:描述


这是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'];

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


长风秋雁
浏览 63回答 1
1回答

慕标琳琳

始终确保在使用 函数访问表单字段的值之前测试已单击提交button。这是因为当服务器加载页面时,服务器尝试检索尚未输入的输入字段的值。就这样。另一种解决方案是使用另一个页面来处理表单提交。issetundefined&nbsp; &nbsp; <?php&nbsp; &nbsp; if(isset($_POST['submit'])){&nbsp; &nbsp; &nbsp;$age = $_POST['age'];&nbsp; &nbsp; &nbsp;$description = $_POST['description'];&nbsp; &nbsp; }&nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">&nbsp; &nbsp; &nbsp; &nbsp; <div class="form-group">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input name="age" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <label>Description</label>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <textarea name="description" rows="4" cols="50" class="form-control" value=""></textarea>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <button name="submit" value="save">Save</button>&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; </form>
打开App,查看更多内容
随时随地看视频慕课网APP