Page 1 of 1
Javscript Timeout Submit
Posted: Sat Aug 26, 2006 6:42 pm
by paqman
I'm near completion of an order form which will automatically log out the user after 15 mins of inactivity. The problem is for the step which has a file upload, the form.submit(); function won't work in javascript. The timeout which calls the function still does, but it won't submit. Does anyone know what might be causing this (I'm wondering if it's the ENCTYPE="multipart/form-data" which lets the file upload correctly.) or have any thoughts of how to fix it? Any ideas/help would be greatly appreciated!
Posted: Sat Aug 26, 2006 6:48 pm
by feyd
Post the code.
How does forcing a submission of a page form constitute a logout?
For future reference: Javascript is a Client Side question.
Posted: Sat Aug 26, 2006 7:31 pm
by paqman
I've tried to make my form as user-friendly as possible, so there are a few extra things in it. When a user edits a page (there are 7 total) the page they came from is saved as $refer. Once they edit and submit the page, they are sent to $refer. Here's the troublesome stage (stage 1), as well as the initial code:
Code: Select all
// start session
if(isset($_SESSION["s_name"])) { ?>
//here's the timeout javascript code, which is currently set to 5 seconds
<script type="text/javascript">
<!--
function leavePage() {
document.form.refer.value = "logout";
document.form.submit(); }
setTimeout("leavePage()",5000);
// -->
</script><?
// if $stage is not set, make it 1
if(!isset($stage) && !isset($cmd)) { $stage = 1; }
// stage 1: Design
if($stage == 1) {
$sql2 = mysql_query("SELECT * FROM weborder WHERE username_3 = '$s_username'");
while($f=mysql_fetch_array($sql2))
{
$color_1 = $f["color_1"];
$logo_1 = $f["logo_1"];
$logo_info_1 = $f["logo_info_1"];
$feel_1 = $f["feel_1"];
$splash_1 = $f["splash_1"];
$other_1 = $f["other_1"]; ?>
<form method="post" action="order.php?stage=save1" ENCTYPE="multipart/form-data" name="form">
<center><textarea rows=15 cols=75 name="color_1"><? echo $color_1; ?></textarea></center><br><br>
<? if(strlen($logo_1) > 0) { ?><a href="upload/<? echo $s_username; ?>_logo.<? echo $logo_1; ?>" target="logo">View current uploaded picture</a><br><br><? } ?>
<center>
<input type="file" name="logo_file" size=80><br>
<textarea rows=15 cols=75 name="logo_info_1"><? echo $logo_info_1; ?></textarea></center><br><br>
<center><textarea rows=15 cols=75 name="feel_1"><? echo $feel_1; ?></textarea></center><br><br>
<center><textarea rows=15 cols=75 name="splash_1"><? echo $splash_1; ?></textarea></center><br><br>
<center><textarea rows=15 cols=75 name="other_1"><? echo $other_1; ?></textarea></center><br><br>
<? // here's the hidden field which stores the referring url, or is changed to 'logout' when the timeout is used ?>
<input type="hidden" value="<? echo $refer; ?>" name="refer">
<input type="submit" name="submit" value="Continue"><br>
<? }
}
// stage 1 save
if($stage == "save1") {
$color_1 = $_POST["color_1"];
$logo_file = $_POST["logo_file"];
$logo_info_1 = $_POST["logo_info_1"];
$feel_1 = $_POST["feel_1"];
$splash_1 = $_POST["splash_1"];
$other_1 = $_POST["other_1"];
$refer = $_POST["refer"];
if(is_uploaded_file($_FILES['logo_file']['tmp_name'])) {
echo 'theres a picture here!<br>';
$uploaddir = '/home/paqmanwe/public_html/bnew/upload/';
$uploadfile = $uploaddir . basename($_FILES['logo_file']['name']);
move_uploaded_file($_FILES['logo_file']['tmp_name'], $uploadfile);
$ext = substr($uploadfile, -3, 3);
rename($uploadfile, $uploaddir.$s_username."_logo.".$ext);
$prsql = "UPDATE weborder SET logo_1='$ext' WHERE username_3='$s_username'";
if(mysql_query($prsql)) { echo 'mysql success!<br>'; } else { echo 'mysql failure<br>'; }
echo 'Image successfully uploaded<br>'; }
$sql = "UPDATE weborder SET color_1='$color_1',logo_info_1='$logo_info_1',feel_1='$feel_1',splash_1='$splash_1',other_1='$other_1',finished1='1' WHERE username_3='$s_username'";
$result = mysql_query($sql);
// regular action to take (not timeout)
if($refer !== "logout") { ?>
<body onload=setTimeout("location.href='order.php?stage=<? if(strlen($refer) > 0) { echo $refer; } if(strlen($refer) == 0) { echo "2"; } ?>'",1200)>
<p>Entries saved successfully. Continuing...</p> <? }
// when timeout is set
if($refer == "logout") {
$sql2 = "UPDATE weborder SET finished1='0' WHERE username_3='$s_username'";
$result2 = mysql_query($sql2); ?>
<body onload=setTimeout("location.href='order.php?cmd=logout&display=timeout'",1200)>
<p>Session timed out. Progress saved. Redirecting...</p> <? }
}
This is just a piece of the file, so don't worry that there's more { than }s. This code works for every other step, except this one.