Solved

Displaying user details in several web forms.

Posted on 2004-03-24
11
207 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:rincewind666
  • 5
  • 4
  • 2
11 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 10672238
I suggest you start reading http://stein.cshl.org/WWW/software/CGI/

0
 

Author Comment

by:rincewind666
ID: 10694262
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
0
 
LVL 48

Accepted Solution

by:
Tintin earned 250 total points
ID: 10700004
Assuming your HTML sample has a form tags, eg:

<form action="/cgi-bin/script.cgi" method="post">
...
</form>

in it, then your Perl script will look like:

#!/usr/bin/perl
use strict;
use CGI;

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

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>

My name is $name and my age is $age<br>

</body>
</html>

HTMLCODE


0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 10701973
security improvement:
  my $name = $q->escapeHTML($q->param('name'));
  my $age  = $q->escapeHTML($q->param('age'));
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10709438
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.
0
 

Author Comment

by:rincewind666
ID: 10727182
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
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 250 total points
ID: 10727614
hmm, this will end in a cumbersome solution, better you use a session object somehow on the server, and just pass over the sessionID identifying this object.
Anyway, you need use hidden fields (just one example):

..
my $name = $q->escapeHTML($q->param('name'));
..
<FORM ACTION="http://demo.com/cgi-bin/test/form2.cgi" METHOD="POST">
<input type="hidden" name="name" value="$name" />
0
 

Author Comment

by:rincewind666
ID: 10727985
I am now getting "File Not found" after clicking the submit button.
0
 

Author Comment

by:rincewind666
ID: 10728035
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.

0
 
LVL 48

Expert Comment

by:Tintin
ID: 10728211
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.
0
 

Author Comment

by:rincewind666
ID: 10740389
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!)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question