0

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?

Raphael_b
  • 1,470
  • 3
  • 16
  • 30
  • What is the output of your PHP? – Turnip Nov 25 '14 at 13:50
  • this is a shot in the dark, remove that newline, and put it in one line instead: `?>>` maybe related http://stackoverflow.com/questions/10585759/why-isnt-my-textareas-placeholder-showing-up – Kevin Nov 25 '14 at 13:53
  • This code should work. Can you post the code before the `textarea` definition? – S.Pols Nov 25 '14 at 13:57
  • @uʍopǝpısdn $description_roster is a string 'a team composed of players' – Raphael_b Nov 25 '14 at 14:03
  • Not a solution, but you might want to [escape the description](http://php.net/htmlspecialchars) first, in case you have a description like `Dwayne "The Rock" Johnson`. – cloudfeet Nov 25 '14 at 14:04
  • @cloudfeet actually that's a very good point. Thanks – Raphael_b Nov 25 '14 at 14:08

3 Answers3

1

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>
sebbzzz
  • 471
  • 4
  • 14
  • This isn't the problem. Also the question had a check if `description_roster` exists which is a good thing. So your solution is worser then the question self. – S.Pols Nov 25 '14 at 13:55
1

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=>.

cloudfeet
  • 12,156
  • 1
  • 56
  • 57
0

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

L.Butz
  • 2,466
  • 25
  • 44
Raphael_b
  • 1,470
  • 3
  • 16
  • 30