Forum Moderators: coopster & phranque

Message Too Old, No Replies

Displaying values after a form submission

         

th1chsn

12:29 am on Sep 19, 2003 (gmt 0)

10+ Year Member



Hello, I am using formmail to process the form on my site. After they submit the form they go to another page to sign up to this program.

Is there a way that I can capture the values that they used in the form and pre-fill them into the next form so they don't have to type them over again?

Thanks in advance for the help.

MonkeeSage

1:15 am on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



FormMail puts all the form input values into a multi-dimensional array called %Form (and also in %Config) after it completes the parse_form subroutine. You can access any form input value after that using this syntax:
$Form{'name'}
.

so if you have an input with name="color" you can access it's value with

$Form{'color'}
.

Alternately, if you add this line to the top of the file right beneath the shebang line...

use CGI qw(:standard);

...you can access any form input value from any point in the script using this syntax:

param("name")
.

HTH
Jordan

th1chsn

1:38 am on Sep 19, 2003 (gmt 0)

10+ Year Member



Hi Jordan, thank you for response.

Do I have to put anything in the html of the page in order to reference these values? Right now when I put
$Form{'first_name'} in the form field no value is put in only the $Form{'first_name'}.

Randy

MonkeeSage

2:16 am on Sep 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Randy:

Sorry, I misunderstood you, I thought you were trying to get the values so you could generate the HTML dynamically from within the FormMail script. There is no way to get the values with just HTML, AFAIK.

The only know of two ways to make a new form with the values already filled in; the first is to do it from inside the FromMail script...e.g., instead of the thankyou page...

print "Content-type: text/html\n\n"; 
print <<"(END HTML)";
<form name="form2">
<input name="color" type="text" value="$Form{'color'}"/>
</form>
(END HTML)

The second is to use a GET method on your first form (method="GET"), and then redirect to your HTML page with the new form to fill, then use JavaScript to parse the

document.referrer
object, which will contain the form information from the first form, and will look something like...

[somewhere.over.there...]

You basically just use the indexOf() and substring() methods to get the different values...for example,

<script type="text/javascript"> 
<!--
var name = null;
var val = null;

function getVals() {
if (document.referrer) {
name = new Array();
val = new Array();
var ref = document.referrer;
var idx = ref.indexOf("?");
if (idx!= -1) {
ref = ref.substring(idx + 1, ref.length);
}
else {
return "";
}
var arr = ref.split("&");
var tmpArr = new Array();
for (var i = 0; i < arr.length; ++i) {
// tmpArr is multi-dimensional after this,
// first level is name, second is value
tmpArr[i] = arr[i].split("=");
}
for (i = 0; i < tmpArr.length; ++i) {
name[i] = tmpArr[i][0];
val[i] = tmpArr[i][1];
}
return formFill();
}
else {
return "";
}
}

function formFill() {
for (var i = 0; i < name.length; ++i) {
if (name[i] == "recipient") {
document.form2.recipient.value = val[i];
}
else if (name[i] == "email") {
document.form2.email.value = val[i];
}
// etc...
}
}

window.onload = getVals;
//-->
</script>

Jordan

th1chsn

4:39 am on Sep 19, 2003 (gmt 0)

10+ Year Member



Thanks Jordan for your very quick and thorough reply!