Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Displaying user details in several web forms.

Posted on 2004-03-24
11
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
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 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

609 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