duanlie2709 2016-01-30 02:11
浏览 55
已采纳

无法预先填充textarea字段[重复]

This question already has an answer here:

I have a form that lets a user submit things like "header" and "description_1". I take this information an build a simple one page website for them. There's a link that lets them edit the page, which reads the fields back from the database and pre-populates the form with it. The form is pre-populated by setting the value attribute of the fields to the data pulled back from the database. This works fine for input fields (485-490 below) but it doesn't work for textarea fields (493-498 below). I've verified that $description_1 does have the right text but setting the textarea value to this text doesn't get it to show up when the form is displayed. Does anyone know what the problem might be? Thanks.

enter image description here

</div>
  • 写回答

2条回答 默认 最新

  • duanrongpai9556 2016-01-30 02:21
    关注

    Text areas work differently than other input fields. Default values are set by adding your text in between the HTML tags.

    <textarea><? echo $description_1 ?></textarea>
    

    It's been a while since I 've done this but I think you're going to run into some trickiness with carriage returns. To do that you need to convert the values with nl2br. I think it's like this:

    <textarea><? echo nl2br($description_1) ?></textarea>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图的问题
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名