Solved

Displaying user details in several web forms.

Posted on 2004-03-24
11
208 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 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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