Page 1 of 1

TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 4:05 am
by gazzieh
I have a form with a textarea and I want to pre-populate it with relevant data.

I tried:

Code: Select all

<?php echo '<textarea name="thearticle" id="thearticle">'.$row['thearticle'];?>.'</textarea>'; ?>
Yet this does not work. If I simply echo the article piece (outside the textarea) then the article appears and if I remove the textarea from within the PHP and insert the word 'duckling' instead of the variable then that works, but I cannot seem to be able to pre-populate using the variable.

Where am I going wrong?

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 4:52 am
by yacahuma
There is no reason for you to put everything in php. Plus you have and additional ?> in your code

Do it like this. Your code will be easier to maintain.

Code: Select all

<textarea name="thearticle" id="thearticle"><?php echo $row['thearticle']?></textarea>
I prefer the short <?=$row['thearticle']?> But I am not sure is this is going to be depricated

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 5:09 am
by gazzieh
yacahuma wrote:There is no reason for you to put everything in php. Plus you have and additional ?> in your code

Do it like this. Your code will be easier to maintain.

Code: Select all

<textarea name="thearticle" id="thearticle"><?php echo $row['thearticle']?></textarea>
I prefer the short <?=$row['thearticle']?> But I am not sure is this is going to be depricated
Sorry about the additional ?>; wasn't in the code but only in my posting.

I did actually try your suggestion previously and got the same result; nothing.

Code: Select all

<textarea name="thearticle" id="thearticle">
<?php echo $row['thearticle']; ?>
</textarea>
As I say, the interesting thing is that if I post the line <?php echo $row['thearticle'] ?> anywhere outside the form then the contents appear; but not inside the textarea.

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 6:09 am
by yacahuma
did you check the validity of your html?

Re: TEXTAREA filled with variable

Posted: Fri Jun 18, 2010 7:08 am
by Benjamin
:arrow: Duplicate = Locked