I am trying to set up the code so that the it takes the user from one form to a thank you page, then to another form and have some of the info from the first (last name, first name, email) into the second.
I managed to get the code to work in a simple, theoretical form but the form I'm modifying includes some VB script (does that conflict?) with some older HTML standards.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script language="JavaScript" type="text/javascript" src="sub_val.js"></script>
<script language="JavaScript" type="text/javascript" src="cookieForm.js"></script>
</head>
<body onload="cookieForms('open', 'yourform')" onunload="cookieForms('save', 'yourform')">
<!---Max Length fields are accurate to be allowed in the database---> <!---All fields are Varchar in the database except for text_only---> <!--- All Required fields are noted, not all are required. All MM fields for a recipient are listed to use at your disposal. When new custom fields are added to the subscription page, just use the next available field corresponding to the custom field number in MM --->
<form action="http://www.magnetmail.net/actions/subscription_form_action.cfm" method="post" name="yourform" onsubmit="return validate_form ( );"> <!--- URL to action page which will store data ---> <input maxlength="10" name="user_id" type="hidden" value="jmu_" /> <!--- Required field when storing data ---><!--- This field is critical to proper storing of data | it is imperative never to change from: BNAInc--->
<table border="0" cellspacing="5" cellpadding="0">
<tbody>
<tr>
<td>
<div align="right">* E-mail:</div>
</td>
<td><input maxlength="100" name="recipient_email" type="text" /> <!--- Required field when storing data ---></td>
</tr>
<tr>
<td>
<div align="right">* First Name:</div>
</td>
<td><input maxlength="50" name="recipient_first_name" type="text" /><!--- Required field when storing data ---></td>
</tr>
<tr>
<td>
<div align="right">* Last Name:</div>
</td>
<td><input maxlength="50" name="recipient_last_name" type="text" /><!--- Required field when storing data ---></td>
</tr>
<td>
<div align="right">Job Title:</div>
</td>
<td><input maxlength="50" name="custom17" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Organization:</div>
</td>
<td><input maxlength="50" name="recipient_company" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Address 1:</div>
</td>
<td><input maxlength="100" name="recipient_address" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Address 2:</div>
</td>
<td><input maxlength="100" name="recipient_address_2" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">City:</div>
</td>
<td><input maxlength="50" name="recipient_city" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">State:</div>
</td>
<td><input maxlength="50" name="recipient_state" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Zip:</div>
</td>
<td><input maxlength="50" name="recipient_zip" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Country:</div>
</td>
<td><input maxlength="50" name="custom18" type="text" /></td>
</tr>
<td>
<div align="right">Phone:</div>
</td>
<td><input maxlength="50" name="recipient_phone" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Fax:</div>
</td>
<td><input maxlength="50" name="recipient_fax" type="text" /></td>
</tr>
<tr>
<td>
<div align="right">Website:</div>
</td>
<td><input maxlength="100" name="custom19" type="text" /> <!-- Graduation year, custom field #8 --></td>
</tr>
<tr>
<td></td>
<td>
<div align="center"><input name="set" type="submit" value="Submit" /></div>
</td>
</tr>
</tbody>
</table>
<br /> *<em> denotes required field</em> <!---URLs below were added as examples, they should be replaced with where the user should receive confirmation.---> <input name="subgroups" type="hidden" value="499706" /> <!--- Required field when storing data ---><!--- GROUPIDS can be found in the URL of the management of that group in MagnetMail --->
<input name="custom_validation_redir" type="hidden" value="http://maic.jmu.edu/development/news_thanks.html" /> <!---URL to where the original HTML form lives | must be a valid URL--->
<input name="custom_end_location" type="hidden" value="http://maic.jmu.edu/development/news_thanks.html" /> <!--- Required field when storing data ---> <!---URL to where the confirmation page should go to | must be a valid URL. Ahem.--->
</form>
</body>
</html>
And here's the cookie script straight off da interweb.
//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->
//<!-- Original: Nick Baker -->
//<!-- Begin
// Cookie Functions //////////////////// (:)
// Set the cookie.
// SetCookie('your_cookie_name', 'your_cookie_value', exp);
// window.onload="cookieForms('open', 'yourform')";
// window.onunload="cookieForms('save', 'yourform')">
// Get the cookie.
// var someVariable = GetCookie('your_cookie_name');
var expDays = 100;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) { endstr = document.cookie.length; }
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// cookieForms saves form content of a page.
// use the following code to call it:
// <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">
// It works on text fields and dropdowns in IE 5+
// It only works on text fields in Netscape 4.5
function cookieForms() {
var mode = cookieForms.arguments[0];
for(f=1; f<cookieForms.arguments.length; f++) {
formName = cookieForms.arguments[f];
if(mode == 'open') {
cookieValue = GetCookie('saved_'+formName);
if(cookieValue != null) {
var cookieArray = cookieValue.split('#cf#');
if(cookieArray.length == document[formName].elements.length) {
for(i=0; i<document[formName].elements.length; i++) {
if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }
else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }
else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
}
}
}
}
if(mode == 'save') {
cookieValue = '';
for(i=0; i<document[formName].elements.length; i++) {
fieldType = document[formName].elements[i].type;
if(fieldType == 'password') { passValue = ''; }
else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
else { passValue = document[formName].elements[i].value; }
cookieValue = cookieValue + passValue + '#cf#';
}
cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
SetCookie('saved_'+formName, cookieValue, exp);
}
}
}
// End -->
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
Any suggestions would be GREATLY appreciate! :)