The below .cgi script works perfectly with the HTML form post just beneath it. :trockon:
#Script beginning#
#!/usr/bin/perl -wT
use strict;
use CGI ':standard';
my $item_name;
my $amount;
my $business;
my $item_number;
my $notify_url;
my $return;
my $cancel_return;
my $shipping;
my $cbt;
my $src;
$item_name = param('item_name');
$amount = param('amount');
$business = param('business');
$item_number = param('item_number');
$notify_url = param('notify_url');
$return = param('return');
$cancel_return = param('cancel_return');
$shipping = param('shipping');
$cbt = param('cbt');
$src = param('src');
print "Content-type: text/html\n\n";
print<<ENDHTML;
<HTML>
<BR>
<HEAD>
<TITLE>CGI Test</TITLE>
<td width="60%" valign="top">
<form action="https://www.example.com/cgi-bin/webscr"><BR>
<input type="hidden" name="cmd" value="_xclick"><BR>
<input type="hidden" name="item_name" value="$item_name"><BR>
<input type="hidden" name="item_number" value="$item_number"><BR>
<input type="hidden" name="amount" value="$amount"><BR>
<input type="hidden" name="business" value="$business"><BR>
<input type="hidden" name="notify_url" value="$notify_url"><BR>
<input type="hidden" name="return" value="$return"><BR>
<input type="hidden" name="cancel_return" value="$cancel_return"><BR>
<input type="hidden" name="shipping" value="$shipping"><BR>
<input type="hidden" name="cbt" value="$cbt"><BR>
<input type="image" src="$src"><BR>
</form>
</td>
</tr>
</HEAD>
</HTML>
ENDHTML
#ENDSCRIPT#
Below is the HTML form post:
<form action="https://www.forumexample.com/cgi-bin/example.cgi" method="post">
<input type="hidden" name="item_name" value="product">
<input type="hidden" name="item_number" value="123r">
<input type="hidden" name="amount" value="10.00">
<input type="hidden" name="business" value="example">
<input type="hidden" name="notify_url" value="example">
<input type="hidden" name="return" value="example">
<input type="hidden" name="cancel_return" value="example">
<input type="hidden" name="shipping" value="example">
<input type="hidden" name="cbt" value="example">
<input type="image" src="example" height="90" width="90">
</form>
End HTMl form post
Again the above examples perform perfectly. Printing my <, and " HTML symbols to the screen. It is great in order to display the end result of what the HTML code would appear as. Now I wish to make it function, so that if no value is passed for one of the variables, the .cgi script will not print the line of code. Below is what I have attempted as far as an if else statement, and the script breaks throwing an Internal Server error. I have checked permissions, and the script will function perfectly once I remove the if, else statments.
print "Content-type: text/html\n\n";
print<<ENDHTML;
<HTML>
<HEAD>
<table border="1" width="100%" cellpadding="10">
<tr>
<td width="40%" valign="top">
print <form action="https://www.example.com/cgi-bin/webscr"><BR>
print <input type="hidden" name="cmd" value="_xclick"><BR>
if ($item_name eq 'NULL') {
print ;
} else {
print <input type="hidden" name="item_name" value=>
}
</td>
</HEAD>
</HTML>
ENDHTML
:chomp:
Now I do realize that if else statements work perfectly with perl only syntax involved. However, I am unable to find how I can print the symbols such as <, ", -. Which is essential for me to print, because I am hoping for someone to be able to copy and paste the end result of a form post creation process. Not every person will want an end result that contains each and every variable.
Please someone save me from this! It seems as if I am missing something rater fundamental.
Printing HTML in perl which use if, else statmentsPrinting HTML in perl which use if, else statments
Page 1 of 1
2 Replies - 1445 Views - Last Post: 03 April 2007 - 11:03 PM
Replies To: Printing HTML in perl which use if, else statments
#2
Re: Printing HTML in perl which use if, else statments
Posted 02 April 2007 - 11:18 AM
I think that you need to check out your print statements...try putting quotation marks or something around both of them. So that if there's no value in $item_name you print '';, and if there IS a value you put quotation marks around what you're printing out.
#3
Re: Printing HTML in perl which use if, else statments
Posted 03 April 2007 - 11:03 PM
You can't have an if/else block in the middle of a heredoc, but even if you fix that, I don't understand what your basic question is.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|