View Full Version : How to pass info from form field?
alpherjo
05-28-2002, 12:36 AM
I have a page with a simple data capture form. I'm trying to figure out the best way to pass the information put in one of the fields so that the user-inputted data is put in the same field on the next page.
Can anyone help me out with this? Any insight would be great.
Thanks!
Jon Hanlon
05-28-2002, 02:26 AM
You either use a cookie, or the search part of the URL, or asp/cgi.
alpherjo
05-28-2002, 08:42 PM
Could you explain that a little more?
Also, the site doesn't support asp or php (wish it did), so I am just using the basic FormMail script like found at "Matt's Scripts".
So what I have is one page where someone puts in their info (name, email) in a textarea. After they hit submit, they are taken to another page where they can add some other info. However, if they add info, I also need their name and email to go with it. Instead of them having to add it again, I would like for it to just show up in those 2 field areas.
But I'm not sure how to do this using this type of form. I also heard I could maybe use javascript to accomplish this.
ANY help would be great!
Thanks!
screamer
06-29-2002, 12:07 PM
use this script in your next page to process data in your URL say
http://www.yourdomain.com/home.html?field1=data1&field2=data2
where field1 is your original page fieldname
and data1 is your original page data
obviously u need a <form method ="get" action="yournextURL.html"> in your original HTML
this script will parse the data in the resulting URT
and u call the data using FORM_DATA["field1"]
<script language="JavaScript">
function createRequestObject() {
FORM_DATA = new Object();
// The Object ("Array") where our data will be stored.
separator = ',';
// The token used to separate data from multi-select inputs
query = '' + this.location;
// Get the current URL so we can parse out the data.
// Adding a null-string '' forces an implicit type cast
// from property to string, for NS2 compatibility.
query = query.substring((query.indexOf('?')) + 1);
// Keep everything after the question mark '?'.
if (query.length < 1) { return false; } // Perhaps we got some bad data?
keypairs = new Object();
numKP = 1;
// Local vars used to store and keep track of name/value pairs
// as we parse them back into a usable form.
while (query.indexOf('&') > -1) {
keypairs[numKP] = query.substring(0,query.indexOf('&'));
query = query.substring((query.indexOf('&')) + 1);
numKP++;
// Split the query string at each '&', storing the left-hand side
// of the split in a new keypairs[] holder, and chopping the query
// so that it gets the value of the right-hand string.
}
keypairs[numKP] = query;
// Store what's left in the query string as the final keypairs[] data.
for (i in keypairs) {
keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
// Left of '=' is name.
keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
// Right of '=' is value.
while (keyValue.indexOf('+') > -1) {
keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
// Replace each '+' in data string with a space.
}
keyValue = unescape(keyValue);
// Unescape non-alphanumerics
if (FORM_DATA[keyName]) {
FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
// Object already exists, it is probably a multi-select input,
// and we need to generate a separator-delimited string
// by appending to what we already have stored.
} else {
FORM_DATA[keyName] = keyValue;
// Normal case: name gets value.
}
}
return FORM_DATA;
}
FORM_DATA = createRequestObject();
// This is the array/object containing the GET data.
// Retrieve information with 'FORM_DATA [ key ] = value'.
// -->
</script>
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.