www.webdeveloper.com
Results 1 to 6 of 6

Thread: Sticky textarea not 'sticking'

  1. #1
    Join Date
    Nov 2007
    Location
    Melbourne, Australia
    Posts
    36

    Sticky textarea not 'sticking'

    Hi Guys,

    I'm wanting to add data to this textarea then go to another page or log on at a later date and add more data to it. But on refreshing or reloading the page, the data (text) disappears.

    I copied the below code from a tutorial and thought that it would do the job.

    I'm using php 4.3.9

    Any help would be appreciated.

    PHP Code:
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <textarea name="jammplantext" cols="50" rows="35"><?php if(isset($_POST['jammplantext'])) echo $_POST['jammplantext']; ?></textarea>
    <input type="submit" name="submit" value="Submit Changes">
    </form>

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Your code assumes that you have the parameter "jammplantext" set somewhere in the POST request. if you're refreshing the page, you're more likely than not keeping the POST data. you'll want a database, or some kind of flat file to read the data from.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Nov 2007
    Location
    Melbourne, Australia
    Posts
    36
    Thanks Chazzy,
    Your code assumes that you have the parameter "jammplantext" set somewhere in the POST request.
    Sorry, I'm a newbie to php - Can you please elaborate?

  4. #4
    Join Date
    Jan 2011
    Posts
    2

    I think you're just missing the curly brackets...

    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <textarea name="jammplantext" cols="50" rows="35"><?php if(isset($_POST['jammplantext'])) { echo $_POST['jammplantext']; } ?></textarea>
    <input type="submit" name="submit" value="Submit Changes">
    </form>

  5. #5
    Join Date
    Oct 2007
    Posts
    370
    Quote Originally Posted by Stevo22 View Post
    Thanks Chazzy,

    Sorry, I'm a newbie to php - Can you please elaborate?
    Chazzy is right.

    When you submit a form, it can either send GET or POST data. GET shows up in the URL. POST data is sent behind the scenes. Once the server has parsed that request, the POST data no longer exists.

    When you post that form, the field should re-populate (after you add the curly braces mentioned by calluna) because the POST data is there, at that time. When you leave and come back, there is no POST data until you submit the form, so the textarea will be empty.

    Refreshing the page should work as long as you choose to re-send the post data. Using the back button will probably work in most situations.

    If you want the textarea to re-populate with data from an earlier visit, you'd have to store that information somewhere, (write it to a file or put it in a database) access it when you come back, and then echo that data into the textarea. If you want that to happen only for a specific visitor, then you'll need user validation too.

    I just realized this was a resurrected thread. o_0
    Last edited by TecBrat; 01-12-2011 at 12:40 PM. Reason: to make a comment

  6. #6
    Join Date
    Jan 2011
    Posts
    2
    Right, I'm making the assumption that there has been some sort of code written previously in the page that addresses the POST issue. I just noticed the brackets were missing. I used this code in an email form and it works perfectly so long as the curly brackets are in place.

    I realize it was an old thread, just thought it would be good to resolve since it comes up in a search...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles