BlueDolphin
BlueDolphin

Reputation: 35

How do I get the text to remain in textarea after saving it with php?

I am making a notes page. The user can add notes in a textarea and press save and it is saved into a database. Once you press save the note is no longer there and will clear out. I want the note to still be there when the page reloads. I have done some research in this area and haven't found much luck. Is there any way to press save yet leave the text on screen?

Upvotes: 0

Views: 306

Answers (3)

A simpler alternative would be the following one.

<textarea>
  <?php  
    print (!empty($_POST["notes"]) ? filter_var($_POST["notes"], FILTER_SANITIZE_STRING) : null); 
  ?>
</textarea>

$_POST should be sanitized for malicious inputs, but that's a simple example which will get you running as a start.

Upvotes: 0

Ranjith
Ranjith

Reputation: 2819

For that, you need to check, if any post values are sets inside the <textarea>

<textarea name="notes">

   <?php 
      if( isset($_POST['notes']) )
       echo $_POST['notes'];
   ?>

</textarea>

Upvotes: 2

chandresh_cool
chandresh_cool

Reputation: 11830

After submitting the form just echo the post value of the texarea. Something line this if you want to show that in textarea

<textarea name="context"><?php echo $_POST['context'];?></textarea>

Upvotes: 1

Related Questions