Link to home
Start Free TrialLog in
Avatar of rincewind666
rincewind666

asked on

Displaying user details in several web forms.

I have several web forms. When a user fills out the first form, I want these details to be used/displayed in the following forms and so on. I need to use perl.

I am a novice.  Your help would be greatly appreciated.
Avatar of Tintin
Tintin

I suggest you start reading http://stein.cshl.org/WWW/software/CGI/

Avatar of rincewind666

ASKER

Is it possible to use hidden fields? What am I doing wrong?  I am a complete novice. Many thanks for your help.

The first script is as follows:

<table width="50%" border="0" cellspacing="5" cellpadding="5">
  <tr>
    <td width="20%">Name</td>
    <td width="80%"><input type="text" name="name"></td>
  </tr>
  <tr>
    <td>Age</td>
    <td><input type="text" name="age"></td>
  </tr>
  <tr>
    <td>Comments</td>
    <td><textarea name="comments"></textarea></td>
  </tr>
</table>
<p>
  <input type="submit" name="Submit" value="Submit">
</p>  <input type="submit" name="Submit" value="Submit">
</p>

</body>
</html>

EndOfHTML

The second script is as follows:

#!/usr/bin/perl
print "Content-type:text/html\n\n";

print <<EndOfHTML;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

I WANT TO SHOW SOME VARIABLES HERE SUCH AS
My name is $name






</body>
</html>


EndOfHTML
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
security improvement:
  my $name = $q->escapeHTML($q->param('name'));
  my $age  = $q->escapeHTML($q->param('age'));
Good suggestion ahoffmann.

For others who may not know the importance of escaping the input, you can leave yourself open to cross site scripting exploits, where people can post arbitorary code via the form, for example some malicious Javascript to redirect you to a "bad" site.
This only seems to work for carrying variables over to the following script. I need to carry all variables onwards over several scripts and list them at the end.

All variables listed in scripts 1, 2, and 3 should appear in script 4 but when I try this, all I get from Script 4 is:

NAME:                                        (variable in Script 1 - user inputs "Tom" but nothing appears in Script 4)

EMAIL:                                       (variable in Script 2 - user inputs "test@demo.com" but nothing appears in Script 4)

COMPANY: ABC Company             (variable in Script 3 - OK)

################ SCRIPT 1:

#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;


print $q->header;
print <<HTMLCODE;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM ACTION="http://demo.com/cgi-bin/test/form2.cgi" METHOD="POST">

<P>
<TABLE>
 
  <TR>
    <TD>Name: <INPUT name=name></TD></TR>
  <TR>
    <TD><INPUT type=submit value=Submit> <INPUT type=reset value=Reset></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR></TABLE></P>
</BODY>
</HTML>


HTMLCODE

################ SCRIPT 2

#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;
my $name = $q->escapeHTML($q->param('name'));


print $q->header;
print <<HTMLCODE;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM ACTION="http://demo.com/cgi-bin/test/form3.cgi" METHOD="POST">

<P>
<TABLE>
 
  <TR>
    <TD>Email: <INPUT name=email></TD></TR>
  <TR>
    <TD><INPUT type=submit value=Submit> <INPUT type=reset value=Reset></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR></TABLE></P>
</BODY>
</HTML>


HTMLCODE

################ SCRIPT 3

#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;
my $name = $q->escapeHTML($q->param('name'));
my $email = $q->escapeHTML($q->param('email'));


print $q->header;
print <<HTMLCODE;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM ACTION="http://demo.com/cgi-bin/test/form4.cgi" METHOD="POST">

<P>
<TABLE>
 
  <TR>
    <TD>Company: <INPUT name=company></TD></TR>
  <TR>
    <TD><INPUT type=submit value=Submit> <INPUT type=reset value=Reset></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR>
  <TR>
    <TD></TD></TR></TABLE></P>
</BODY>
</HTML>


HTMLCODE

################ SCRIPT 4

#!/usr/bin/perl
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $q = new CGI;
my $name = $q->escapeHTML($q->param('name'));
my $email = $q->escapeHTML($q->param('email'));
my $company = $q->escapeHTML($q->param('company'));



print $q->header;
print <<HTMLCODE;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<FORM ACTION="http://demo.com/cgi-bin/test/finish.cgi" METHOD="POST">
<p align="center"><font color="#000000" face="Arial"><big><strong>Thank You
$name</strong></big></font></p>

<p align="left">&nbsp;</p>

<hr>

<p align="left"><font face="Arial" color="#000080"><big>You entered the
following:</big></font></p>



<p align="left"><font face="Arial" color="#000080"><big>NAME: $name</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>EMAIL: $email</big></font></p>
<p align="left"><font face="Arial" color="#000080"><big>COMPANY: $company</big></font></p>

<P>
<INPUT type=submit value=Submit>
</P>

</body>
</html>

HTMLCODE
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am now getting "File Not found" after clicking the submit button.
Sorry - wrong error.  I am trying to do many things at once. The error on this script reads:

Software error:
Can't find string terminator "HTMLCODE" anywhere before EOF at form2.cgi line 11.

The error you are getting indicates that you don't have a closing HTMLCODE terminator.  This could either be because you have mispelt it or you have whitespace before it.
Many thanks for your help. This now seems to work (at least in testing!). Even 500 points (the maximum) cannot go on forever so I have awarded the points for this.  However I would like to extend this so I have placed another question (regarding required fields) for this.

Another 500 points for anyone who can help (and my grateful thanks!)