doutao1282
doutao1282
2014-11-25 13:41

HTML表单:在输入中显示文本(textarea)

I have a form that I pre-fill with my database data. It is working perfectly for all my input. I have a text (that I enter in my database using a textarea). But when I am using the following the text does show in the text area (if I change it to input it is working but I do not have several lines and column allowed with textarea)

<textarea 
    rows="4"
    class="form-control" 
    name="roster_description" 
    id="roster_description" 
    placeholder =
        <?php if ($description_roster){
                echo '"'.$description_roster.'"'; 
            } else {
                echo "";
            }?>>
</textarea>

any ideas?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dongtingxiao4697 dongtingxiao4697 7年前

    Just tested it and it works:

    <textarea 
        rows="4"
        class="form-control" 
        name="roster_description" 
        id="roster_description" 
        placeholder = "<?php if ($description_roster) echo $description_roster;?>">
    </textarea>
    
    点赞 评论 复制链接分享
  • dsoy71058 dsoy71058 7年前

    Ok no clue why but the following is working:

    <textarea class="form-control" id="description_roster" 
              name="description_roster" rows="4"
              placeholder=<?php
                             if ($description_roster){
                                 echo '"'.$description_roster.'"';
                             } else {
                                 echo "";
                             }
                           ?>
    ></textarea>
    

    Thanks to those who had a look

    点赞 评论 复制链接分享
  • dongxing4643 dongxing4643 7年前

    The issue was that your statement:

    echo "";
    

    doesn't produce quotation marks - it produces the empty string. What you want is to replace this with:

    echo '""';
    

    which will produce placeholder=""> instead of placeholder=>.

    点赞 评论 复制链接分享