/    Sign up×
Community /Pin to ProfileBookmark

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.

[code=php]<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>[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@chazzyJan 28.2008 — 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.
Copy linkTweet thisAlerts:
@Stevo22authorJan 28.2008 — Thanks Chazzy,
Your code assumes that you have the parameter "jammplantext" set somewhere in the POST request.[/QUOTE]
Sorry, I'm a newbie to php - Can you please elaborate?
Copy linkTweet thisAlerts:
@calluna8252Jan 12.2011 — <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<textarea name="jammplantext" cols="50" rows="35"><?php if(isset($_
POST['jammplantext'])) [COLOR="Red"]{[/COLOR] echo $_POST['jammplantext']; [COLOR="Red"]}[/COLOR] ?></textarea>

<input type="submit" name="submit" value="Submit Changes">

</form>
Copy linkTweet thisAlerts:
@TecBratJan 12.2011 — Thanks Chazzy,

Sorry, I'm a newbie to php - Can you please elaborate?[/QUOTE]


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
Copy linkTweet thisAlerts:
@calluna8252Jan 12.2011 — 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...
×

Success!

Help @Stevo22 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...