Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retaining data where from and script are seperate files?

Status
Not open for further replies.

cyberspace

Technical User
Aug 19, 2005
968
GB
As part of a site I am developing the user has the option to upload a file.

There is a size limit and it will only accept a .doc

Currently if there is an error, the form is re-displayed, with an error message - but the data input from the user disappears - which will prove a pain.

I've googled this but it all seems to be where the form and script are the same php file and i can't seem to get it to work.

How do i keep the data entered?

thanks

'When all else fails.......read the manual'
 
the data will be in the relevant superglobal $_POST or $_GET. it is just a question of pre-filling the form fields before echoing them

Code:
<?
$name = (isset($_POST['name'])) ? $_POST['name'] : "";
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="text" name="name" value="[red]<?=$name?>[/red]" />
<input type="submit" name="submit" value="submit">
</form>
 
Thanks for that.

the thing is, if the action is <?=$_SERVER['PHP_SELF']?> though, how does it know to pass it to the processing script? As this just passes it back to itself.

This is the problem i was having

'When all else fails.......read the manual'
 
fine, change the action to the processing script. it was just an example of how to prefill the form.
 
e.g.

Code:
<?
session_start();
if (isset($_SESSION['temp'])){
	$temp = unserialize($_SESSION['temp']);
}
$name = isset($temp['name']) ? $temp['name'] : '';
?>
<form action="processor.php" method="post">
<input type="text" name="name" value="<?=$name?>" />
<input type="submit" name="submit" value="submit" />
</form>

Code:
<?
session_start();
$_SESSION['temp'] = serialize ($_POST);
session_write_close();
header('Location: form.php');
?>
 
ah ok - thanks- still having problems however. To test i simply entered an if statement, saying if there is somethng in the upload field, go to the page (using header).

But when it goes back to the page - the field is not prefilled?



'When all else fails.......read the manual'
 
sorry - i replied before i saw your second post - i will try again!

'When all else fails.......read the manual'
 
right i think i am starting to get somewhere.

Two more issues now though:

Firstly - when you go to enter something into the text box, the cursor appears half way along the line. I tried this:

Code:
$summary = isset($temp['summary']) ? $temp['summary'] : '';
$summary = trim($summary);

To no avail.

Secondly, since a user may wish to log 2 calls in the same session, i need to unset the temp variable to prevent a new post being pre-filled.

To do this i did:

Code:
unset($_SESSION['temp']);

after the SQL statements in the processing script - however this doesnt work either.

Thanks so far!

'When all else fails.......read the manual'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top