954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to display the html form output on the same page using perl script ?

Hi,

Please see the below one :

#!c:/perl/bin/perl
use CGI qw(:all);

print "Content-type:text/html\n\n";
print <<EndOfHTML;
<html><head><title>Print Environment</title></head>
<body>
<FORM action="sample.cgi" method="POST">
First Name: <input type="text" name="first_name">  

Last Name: <input type="text" name="last_name">

<input type="submit" value="Submit">
</FORM></body>
EndOfHTML


From this, i don't know to proceed. There are two text box withFirst Name and the Last Name. When submitting the form by clicking "submit button", the First Name and the Last Name should display on the same page, that is at the bottom of the two text boxes. Please help me out. Thanks in advance

jacksantho
Junior Poster
163 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
 
#!/usr/bin/perl
use strict;
use warnings;

use CGI qw(:all);

#Create a new CGI object
my $cgi = new CGI;
my $this_url = $cgi->url(); #Save this script's url
my $first = $cgi->param('first_name');
my $last = $cgi->param('last_name');

print "Content-type:text/html\n\n";
print <<EndOfHTML;
<html><head><title>Generating Self-Referential URLs</title></head>
<body>
<FORM action="$this_url" method="POST">
First Name: <input type="text" name="first_name">  

Last Name: <input type="text" name="last_name">

<input type="submit" value="Submit">
</FORM>
<p>The name you entered was '$first $last'</p> 
</body>
EndOfHTML
#Put a comment or linefeed after EndOfHTML
#Otherwise perl might not find it.
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

hi,

I am facing Internal Server Error. In Apache Error Log is 
[Wed Mar 02 22:05:24 2011] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : couldn't create child process: 720003: sample2.cgi
[Wed Mar 02 22:05:24 2011] [error] [client 127.0.0.1] (OS 3)The system cannot find the path specified.  : couldn't spawn child process: C:/Program Files/Apache Group/Apache2/cgi-bin/sample2.cgi

The code for sample2.cgi is

#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:all);
#Create a new CGI object
my $cgi = new CGI;
my $this_url = $cgi->url('C:/Program Files/Apache Group/Apache2/cgi-bin/sample2.cgi'); #Save this script's url
my $first = $cgi->param('first_name');
my $last = $cgi->param('last_name');
print "Content-type:text/html\n\n";
print <<EndOfHTML;
<html><head><title>Generating Self-Referential URLs</title></head>
<body>
<FORM action="$this_url" method="POST">
First Name: <input type="text" name="first_name"> 
Last Name: <input type="text" name="last_name">
<input type="submit" value="Submit">
</FORM>
<p>The name you entered was '$first $last'</p>
</body>
EndOfHTML
#Put a comment or linefeed after EndOfHTML
#otherwise perl might not find it

I don't know, what mistake, i am doing? thanks

jacksantho
Junior Poster
163 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
 

The following works for me.
my $this_url = $cgi->url();


Don't put anything between the parentheses. You put the full path to your script file and Apache doesn't understand that. The $cgi->url() method should retrieve the correct url for the script that you are running, so that when you submit your form it should go to the same script containing that form. You can read about this at OBTAINING THE SCRIPT'S URL

d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

hi,

Again, i am facing the same error. In url(), i did not supplied any parameter as you told. Why my script is not running?

regards,
santhanalakshmi

jacksantho
Junior Poster
163 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
 

Hi,

Thanks for your help...i got the output. thanks for your coding

jacksantho
Junior Poster
163 posts since Feb 2011
Reputation Points: 7
Solved Threads: 0
 

Hi,

Thanks for your help...i got the output. thanks for your coding


You're welcome. Please don't forget to mark this thread 'solved'.

d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: