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

无法预先填充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 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题