Gossamer Forum
Home : Products : DBMan : Customization :

Cookie mode for form fields

Quote Reply
Cookie mode for form fields
Dear all,
I have been trying cookie mod made by Eli Finkelman
(http://www.koshervitamin.com/cookie.txt)
It was running great on logon screen.

But I my purpose of using cookies is not for log on screen, but for form fields.

How can I play around with the below script to satisfy my needs, My dbman has 10 form fields including radio button, pull down, and input box:

--------------------------------------------
sub cookie {
# --------------------------------------------------------

print qq~
<SCRIPT LANGUAGE=JAVASCRIPT>
// Extract the value from the cookie at the given offset.

function GetValue( Offset )
{
var End = document.cookie.indexOf (";", Offset);
if( End == -1 )
End = document.cookie.length;

// Return the portion of the cookie beginning with the offset
// and ending with the ";".

return unescape( document.cookie.substring( Offset, End) );
}

function GetCookie( Name )
{
var Len = Name.length;

// Look at each substring that's the same length as the cookie name
// for a match. If found, look up the value and return it.

var i = 0;
while( i < document.cookie.length )
{
var j = i + Len + 1;
if( document.cookie.substring( i, j) == (Name + "=") )
return GetValue( j );
i = document.cookie.indexOf( " ", i ) + 1;
if( i == 0)
break;
}
var a = "";
return a;
}

// Create or change a cookie given its name and value. The name and value
// are required, but the expiration date isn't. Note that if you don't specify
// an expiration date, the cookie only exists for the current session.

function SetCookie( Name, Value, Expire )
{
document.cookie = Name + "=" + escape( Value ) + ";expires=" + Expire;
}

// Write all the cookies for the form1 form.

function WriteCookies()
{
// var Expire = "Friday,25-Feb-2000 12:00:00 GMT";
var Expire = "$cookie_expiration_date";

with( document.form1 )
{
SetCookie( "username", userid.value, Expire );
SetCookie( "password", pw.value, Expire );
}
}

// Load the form with the values in the cookie

function GetCookies()
{
with( document.form1 )
{
userid.value = GetCookie( "username" );
pw.value = GetCookie( "password" );
auth_remember_login.value = GetCookie( "remember_login" );

if ( auth_remember_login.value == "on" ) {
auth_remember_login.checked = true; }

}
}

function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) // Except on the Mac - ahead of its time
date.setTime (date.getTime() - skew);
}

var expdate = new Date ();
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 365)); // 365 days from now

function IsValid()
{
blnValid = true;

with( document.form1 )
{
if(( userid.value == "" ) &#0124; &#0124; ( pw.value == "" ))
{
window.alert( "You must enter both your user name and your password" );
blnValid = false;
}

var Username = userid.value;
var Password = pw.value;

if (auth_remember_login.checked) {
var Remember_login = "on";
}

}
if( blnValid )

if (Remember_login == "on") {
document.cookie = "username=" + Username + ";expires=" + expdate.toGMTString() + ";";
document.cookie = "password=" + Password + ";expires=" + expdate.toGMTString() + ";";
document.cookie = "remember_login=" + Remember_login + ";expires=" + expdate.toGMTString() + ";";
}

if (Remember_login != "on") {
var Expires = "-1";
document.cookie = "username=" + Username + ";expires=" + Expires + ";";
document.cookie = "password=" + Password + ";expires=" + Expires + ";";
document.cookie = "remember_login=" + Remember_login + ";expires=" + Expires + ";";
}

return blnValid;
}

</SCRIPT>~;
}
--------------------------------------------

I appreciate for any help