orange08 Posted April 7, 2009 Share Posted April 7, 2009 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? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted April 7, 2009 Share Posted April 7, 2009 How are you losing it? What exactly is happening between the losing of the value. Are you sending the data and checking it for errors? Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 7, 2009 Share Posted April 7, 2009 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. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 7, 2009 Author Share Posted April 7, 2009 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? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 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. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 7, 2009 Author Share Posted April 7, 2009 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... Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted April 7, 2009 Share Posted April 7, 2009 You have a typo: $meassage=$_POST['message']; should be $message=$_POST['message']; Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 7, 2009 Author Share Posted April 7, 2009 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> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 7, 2009 Share Posted April 7, 2009 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. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 7, 2009 Author Share Posted April 7, 2009 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. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 7, 2009 Share Posted April 7, 2009 <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. Quote Link to comment Share on other sites More sharing options...
orange08 Posted April 8, 2009 Author Share Posted April 8, 2009 <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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.