Jump to content

textarea session value


orange08

Recommended Posts

This looks correct i think not tested.

 

<?php session_start();

if(isset($_POST['submit'])){

$meassage=$_POST['message'];

$_SESSION['message']=$message;

echo"<textarea name='message' cols='20' rows='20'>";

if(isset($_SESSION['message'])){

echo "{$_SESSION['message']}";

}else{};

echo"</textarea>";
}
?>

 

what i want to no if your ,validating the code then how the hell can the message be posted.

Link to comment
Share on other sites

i have a textarea field, and trying to use session to keep the value, but can't be done...so, how can i get back textarea value?

 

i meant i have a form that contains a textarea, after i press the submit button to go to the next page, then when i press the back button to go back to my form again, my textarea field's value that i entered just now will be disappear even though i'm using $_SESSION. so, how can i get back my textarea value when i press the back button?

Link to comment
Share on other sites

The code that's executed after the submit button is click you can populate a session variable. At the start of the page that displays the HTML (ie. the textarea) you can check if the session variable exists and if yes, extract the data from inside it to a variable so it can be displayed inside the textarea.

Link to comment
Share on other sites

The code that's executed after the submit button is click you can populate a session variable. At the start of the page that displays the HTML (ie. the textarea) you can check if the session variable exists and if yes, extract the data from inside it to a variable so it can be displayed inside the textarea.

 

my problem is the session variable for other input fields are exists, except for textarea and file input...

Link to comment
Share on other sites

oh, sorry, maybe i didn't mention properly with my problem...

i can get my session variable for textarea, but fail to display back in the textarea, so when i press the back button, the textarea field is empty...

 

<textarea cols="50" rows="20" name="mytextarea" value="<?php if(!empty($_SESSION['mytextarea']))echo $_SESSION['mytextarea']; ?>"></textarea>

Link to comment
Share on other sites

Pressing "back" doesn't always reload the page - 99% of the time a cached version is displayed so the textarea will be empty because this is the state it was in when the page was loaded (and cached)

 

Try adding a header to the top to make the page expire instantly.

Link to comment
Share on other sites

Pressing "back" doesn't always reload the page - 99% of the time a cached version is displayed so the textarea will be empty because this is the state it was in when the page was loaded (and cached)

 

Try adding a header to the top to make the page expire instantly.

 

can you give an example? i'm new to php.

Link to comment
Share on other sites

<textarea> doesn't contain a 'value' persay.

 

do this :

<textarea cols="50" rows="20" name="mytextarea"><?php if(!empty($_SESSION['mytextarea']))echo $_SESSION['mytextarea']; ?></textarea>

that'll work.

 

a simple check into working with the <textarea> tag would've solved that for you quite quickly.

 

you place whatever you want to be displayed within the textarea in between the <textarea>stuff here</textarea> tags.

Link to comment
Share on other sites

<textarea> doesn't contain a 'value' persay.

 

do this :

<textarea cols="50" rows="20" name="mytextarea"><?php if(!empty($_SESSION['mytextarea']))echo $_SESSION['mytextarea']; ?></textarea>

that'll work.

 

a simple check into working with the <textarea> tag would've solved that for you quite quickly.

 

you place whatever you want to be displayed within the textarea in between the <textarea>stuff here</textarea> tags.

 

thanks a lot, it's work!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.