Page 1 of 1

Retaining previous posted values

Posted: Sat May 17, 2003 3:12 pm
by jarow
I have a form that if submitted correctly posts back to itself with a message that says the record was entered correctly.

what I would like to do is retain the last values entered in some of the fields so that they don't have to retype everything if they want to add addtional records (it's a list of species and many times phylum, class, order do not change.)

i thought I could do it with session variables but it doesn't work.

Basically here is an example

Code: Select all

$_SESSION['phylum']=$_POST['phylum'];


Then I put the session variable in the field like this

Code: Select all

<?php echo $HTTP_SESSION_VARS['phylum']; ?>


But all the previously posted values are cleared when it reposts to itself.

What am I doing wrong.

Thanks

Posted: Sat May 17, 2003 6:44 pm
by llimllib
ok, let me ask a couple things first:

1) Why do you use $_SESSION[] in one place, then $HTTP_SESSION_VARS[] in another? just use $_SESSION if you're coding for PHP 4.2+.

2) Now that we're using $_SESSION exclusively, have you called session_start() at the very beginning (before any HTML is outputted) of every file that accesses the $_SESSION array?

Posted: Sun May 18, 2003 1:23 am
by jarow
I changed the globals so that they now all read $_SESSION[] and they still do not post.

session_start() is at the beginning of the page before any html.

don't understand why it is clearing the posted values

Posted: Mon May 19, 2003 4:02 am
by jarow
Here is the recap if you or anyone has any other ideas.

I am trying to post a form (method = POST) onto itself and retain some of the values the user just entered.

I have called the following before any html

Code: Select all

<?php session_start();
header("Cache-control: private");
$_SESSION['var']=$_POST['var'];?>

I have also created hidden fields for each of the fields I want to use with the following value

Code: Select all

<?php echo $_POST['var'];?>

I have placed this value as a form variable in each of the form fields in which I want to display the previously posted values


I am posting the form to itself

add.php?success=true

(success=true is a Show/IF if the form is entered correctly)

Don´t understand why it´s not working.

Jim

Posted: Mon May 19, 2003 4:40 am
by volka
please post more of your form-code.
If you check your server's error log (or decrease log/display-level) are there undefined index messages?
If you open the requested document in your browser's sourceview, is there something that looks like those values (even if only remote) ?

Posted: Mon May 19, 2003 5:24 am
by []InTeR[]
Does anybody see something bad in do'ing:

Code: Select all

if(isset($_POST))
  $_SESSION = $_POST;