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
Solved

Displaying user details in several web forms.

Posted on 2004-03-24
11
206 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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