Current location: Hot Scripts Forums » Programming Languages » Perl » HTML Form 1 -> Perl -> return response to HTML form 2

HTML Form 1 -> Perl -> return response to HTML form 2

Reply
  #1 (permalink)  
Old 10-17-06, 06:26 AM
Oleks Oleks is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Question HTML Form 1 -> Perl -> return response to HTML form 2

Hi,
I am trying to return response from perl script to the HTML form. Those HTML form and perl file are located on a different servers. HTML form 1 is sending text to the form.pl file. File is processing that text. But, I do not know how to return response from perl file to the HTML form 2. Can somebody help me with this?

The script for HTML form is
Code:
<HTML>
   <HEAD>
     <TITLE>HTML form/TITLE>
   </HEAD>
   <BODY>
      <FORM NAME="form1" ACTION="http://www.domain.com/cgi-bin/form.pl" METHOD="POST">
          <INPUT TYPE="TEXT" NAME="Test" VALUE="" SIZE="18" MAXLENGTH="50"> <br>
          <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Go!">
      </FORM>

      <FORM NAME="form2" METHOD="POST">
          is: <INPUT TYPE="TEXT" NAME="Test" VALUE="" SIZE="16" MAXLENGTH="50">
      </FORM>
   </BODY>
</HTML>
The script for perl file form.pl is
Code:
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";

use LWP::Simple;

$a = <STDIN>;

# Do something simple
$b = substr ($a, 5, length($a)-18);

# print "Befor $a\n";
# print "After $b\n";

# How to return $b results to the HTML Form 2

Last edited by nico_swd; 10-17-06 at 06:38 AM. Reason: Please use [code] wrappers when posting code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-17-06, 02:22 PM
Drunken Perl Coder Drunken Perl Coder is offline
Wannabe Coder
 
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
You probably want to consider using javascript if the data being processed in form1 and entered into form2 is nothing that needs to be done on the server.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-17-06, 02:59 PM
Oleks Oleks is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Drunken Perl Coder
You probably want to consider using javascript if the data being processed in form1 and entered into form2 is nothing that needs to be done on the server.
Hi Drunken Perl Coder,
The real perl script is doing a lot of calculations.
I just simplify example of my perl file in the first post.
So, I need to stick to perl script.

Any idea how to make this
form1 -> perl script ???-> form 2
business works?

Alex
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 10-17-06, 03:54 PM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Why not this?

Quote:
Originally Posted by Oleks
Hi Drunken Perl Coder,
The real perl script is doing a lot of calculations.
I just simplify example of my perl file in the first post.
So, I need to stick to perl script.

Any idea how to make this
form1 -> perl script ???-> form 2
business works?

Alex
Why not have your perl script print form2 in the browser? From your question, you are trying to use PHP methods while using perl. K.I.S.S.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 10-17-06, 04:17 PM
Oleks Oleks is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by curbview.com
Why not have your perl script print form2 in the browser? From your question, you are trying to use PHP methods while using perl. K.I.S.S.
Hi curbview.com,
Well …
That is maybe because I do not know how to do this.
Can you help me with this by modifying an existing HTML and perl codes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-17-06, 07:38 PM
Drunken Perl Coder Drunken Perl Coder is offline
Wannabe Coder
 
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
a simple example based on your simple example:

Code:
#!/usr/bin/perl

use CGI qw/:standard/;
my $Test = param('Test') || undef;

print header,
      start_html('HTML form'),
qq~<FORM NAME="form1" METHOD="POST">
    <INPUT TYPE="TEXT" NAME="Test" VALUE="" SIZE="18" MAXLENGTH="50"> <br>
    <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Go!">
</FORM>

<FORM NAME="form2" METHOD="POST">
is: <INPUT TYPE="TEXT" NAME="blah" VALUE="$Test" SIZE="16" MAXLENGTH="50">
</FORM>~,
end_html;
The script prints the forms instead of trying to use a static html page. This is much simpler than what you propose unless you switched to PHP.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-17-06, 09:47 PM
Oleks Oleks is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Drunken Perl Coder
a simple example based on your simple example:
The script prints the forms instead of trying to use a static html page. This is much simpler than what you propose unless you switched to PHP.
Hi Drunken Perl Coder,
Thank you for your help.
But ….
In your example, perl file will run first until the end of the script and will not wait for data entering in Form 1. Only after this first run user will be able to enter something into the form 1.
How to solve this.

Try this code and you will see my point.

Code:
#!/usr/bin/perl

use CGI qw/:standard/;
my $Test = param('Test') || undef;

print header,
      start_html('HTML form'),
qq~<FORM NAME="form1" METHOD="POST">
    <INPUT TYPE="TEXT" NAME="Test" VALUE="" SIZE="18" MAXLENGTH="50"> <br>
    <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Go!">
</FORM>

<FORM NAME="form2" METHOD="POST">
is: <INPUT TYPE="TEXT" NAME="blah" VALUE="$Test" SIZE="16" MAXLENGTH="50">
</FORM>~,
end_html;


print "First run\n";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-18-06, 02:42 AM
Drunken Perl Coder Drunken Perl Coder is offline
Wannabe Coder
 
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
CGI scripts do not work like command line scripts where the script will wait for user input. You could simulate that behavior by not printing form2 if there is no data recieved from form1.

Last edited by Drunken Perl Coder; 10-18-06 at 02:45 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 10-18-06, 09:31 AM
Oleks Oleks is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Drunken Perl Coder
CGI scripts do not work like command line scripts where the script will wait for user input. You could simulate that behavior by not printing form2 if there is no data recieved from form1.
Hi Drunken Perl Coder,
Yes. Thank you.
This is a perfect idea, not to run that part of the script where all calculations are, if form1 is empty. I can do this by inserting if-else to the perl script to check is form1 an empty.

One more question.
My goal is to display results of perl script into the HTML page.
Is any way how to call perl script from HTML page and to return results from perl script to the HTML page?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 10-18-06, 01:13 PM
Drunken Perl Coder Drunken Perl Coder is offline
Wannabe Coder
 
Join Date: Aug 2006
Posts: 110
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Oleks
My goal is to display results of perl script into the HTML page.
Is any way how to call perl script from HTML page and to return results from perl script to the HTML page?
Why does it have to be a static html page? You can do that but life gets harder when you want to do that with perl. You will be better off using PHP for something like that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
formmail problem gscraper Perl 12 08-27-04 04:06 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 11:15 AM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 10:50 AM


All times are GMT -5. The time now is 04:35 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.