Forum Moderators: coopster & phranque

Message Too Old, No Replies

Passing hidden form variables to another site

         

wmalex59

8:42 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



I'm trying to send a total from my Perl form to a payment gateway website using the hidden variables they require but getting an error message:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
Bareword found where operator expected at d:\64.246.285.165\cgi-bin\makeconfirmTEST.cgi line 329, near ""

Getting a total from this variable:
$myHiddenAmts = $myHiddenAmts . "<input name=\"TotalAmt\" type=\"hidden\" value=\"". $myTotal . "\">\n";

The original script looks like this:
sub CreateHeader
{
my $myHTML = "";
$myHTML = $myHTML . "Content-type: text/html\n\n";
$myHTML = $myHTML . "<html>\n";
$myHTML = $myHTML . "<head>\n";
$myHTML = $myHTML . "<title>GF Trucking Derbies - Registration Payment</title> \n";
$myHTML = $myHTML . "</head>\n";
$myHTML = $myHTML . "<body>\n";
$myHTML = $myHTML . "<form name=\"form1\" method=\"post\" action=\"finalize.cgi\">\n";
$myHTML = $myHTML . "<table align=\"center\">\n";
$myHTML = $myHTML . "<tr>\n";
$myHTML = $myHTML . "<td align=\"center\">\n";
$myHTML = $myHTML . "<font face=\"Humanst521 XBd BT\">\n";
$myHTML = $myHTML . "<span style=\"letter-spacing: 1pt\">\n";
$myHTML = $myHTML . "<span style=\"font-variant: small-caps\">\n";

I changed it to this as per what the payment gateway wanted:

sub CreateHeader
{
my $myHTML = "";
$myHTML = $myHTML . "Content-type: text/html\n\n";
$myHTML = $myHTML . "<html>\n";
$myHTML = $myHTML . "<head>\n";
$myHTML = $myHTML . "<title>GF Trucking Derbies - Registration Payment</title> \n";
$myHTML = $myHTML . "</head>\n";
$myHTML = $myHTML . "<body>\n";
$myHTML = $myHTML . "<form name=\"form1\" method=\"post\" action=\"https://www.payNET.com/process.asp\">\n";
$myHTML = $myHTML . "<input type="hidden" name="ssl_merchant_id" value="46773">\n";
$myHTML = $myHTML . "<input type="hidden" name="ssl_pin" value="FDD3TM">\n";
$myHTML = $myHTML . "<input type="hidden" name="ssl_show_form" value="true">\n";
$myHTML = $myHTML . "<input type="hidden" name="ssl_test_mode" value="false">\n";
$myHTML = $myHTML . "<input type="hidden" name="ssl_amount" value="$myTotal">\n";
$myHTML = $myHTML . "<table align=\"center\">\n";
$myHTML = $myHTML . "<tr>\n";
$myHTML = $myHTML . "<td align=\"center\">\n";

...any help would be appreciated. I'm probably way off base!

rainborick

9:04 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Errors like that are most often simple syntax errors. Start with the line that the error message says is incorrect - line #329. Give it a good looking over. If you're convinced that particular line in OK, you'll need to start working backward in your script from that line in order to spot the problem.

If you're unsure, post the line in question. Believe me, I understand how difficult it is to see errors in code that you've been staring at for hours and hours.

wmalex59

9:39 pm on Apr 27, 2005 (gmt 0)

10+ Year Member



Looks like it's choking up on this line:

$myHTML = $myHTML . "<input type="hidden" name="ssl_merchant_id" value="46773">\n";

rainborick

10:42 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try replacing it with:

$myHTML = $myHTML . "<input type=\"hidden\" name=\"ssl_merchant_id\" value=\"46773\">\n";

When you have a string in quotation marks like this, you have to add a preceeding backslash ("\") character before any embedded quotation mark in the string to show that its a part of the string and not the end of it. This is also true of other special characters like the @ symbol and $ dollar sign. Good luck!

moltar

10:58 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you can use
qq()
syntax.

$myHTML .= qq(<input type="hidden" name="ssl_merchant_id" value="46773">\n);

wmalex59

11:02 am on Apr 28, 2005 (gmt 0)

10+ Year Member



Thanks guys! That got me into the payment gateway. Now, it seems that the payment gateway won't accept my "$myTotal" variable:
<input type="hidden" name="ssl_amount" value="$myTotal">

This is the error message I got when it went through the gateway:

An Error Occurred

Message : The amount supplied in the authorization request appears invalid.

Here's the code that $myTotal results from:

$myTotal=$myRegAmt
+$myOptionsAmt
+$myCaptainAmt
+$myAngler2Amt
+$myAngler3Amt
+$myAngler4Amt
+$myDonationAmt;

# Return HTML that hides these amounts.
my $myHiddenAmts="";

$myHiddenAmts = "\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"RegAmt\" type=\"hidden\" value=\"". $myRegAmt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"OptionsAmt\" type=\"hidden\" value=\"". $myOptionsAmt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"CaptainAmt\" type=\"hidden\" value=\"". $myCaptainAmt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"Angler2Amt\" type=\"hidden\" value=\"". $myAngler2Amt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"Angler3Amt\" type=\"hidden\" value=\"". $myAngler3Amt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"Angler4Amt\" type=\"hidden\" value=\"". $myAngler4Amt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"DonationAmt\" type=\"hidden\" value=\"". $myDonationAmt . "\">\n";
$myHiddenAmts = $myHiddenAmts . "<input name=\"TotalAmt\" type=\"hidden\" value=\"". $myTotal . "\">\n";
$myHiddenAmts = $myHiddenAmts . "\n";

return $myHiddenAmts;

}

rainborick

2:23 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can usually get a lead on problems like this by doing a "View Source" on the HTML page generated by your script that includes the form that's going to your payment gateway. That way you can examine the contents of the bad <input> tag at run time, and see what the value attribute contains. Dollars to doughnuts, you're going to find it contains either nothing or an obviously incorrect value that will hopefully give you a hint as to the source of the problem. Good luck!

rocknbil

3:58 pm on Apr 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to print "$myTotal" to the screen first, make sure it's a valid number and not blank or 0.

If it is, then here is my guess: You are in test mode and the gateway only accepts a specific amount in test mode. I've seen that exact message before, can't remember what gateway it is. :-) Check the developer docs.

Really really important is to check out Moltar's comment on qq. Part of your syntax problems are because you're writing way more code than required, having to add backslashes everywhere, and that makes for forehead-wrenching error-prone late nights. Look how much simpler this is, and it's the exact same output:

$myHiddenAmts = qq¦
<input name="RegAmt" type="hidden" value="$myRegAmt">
<input name="OptionsAmt" type="hidden" value="$myOptionsAmt">
<input name="CaptainAmt" type="hidden" value="$myCaptainAmt">
<input name="Angler2Amt" type="hidden" value="$myAngler2Amt">
<input name="Angler3Amt" type="hidden" value="$myAngler3Amt">
<input name="Angler4Amt" type="hidden" value="$myAngler4Amt">
<input name="DonationAmt" type="hidden" value="$myDonationAmt">
<input name="TotalAmt" type="hidden" value="$myTotal">
¦;

Pick a delimiter, any character (I use pipes because they are seldom used in normal text), put it in front and behind your output, and put qq in front. The only thing you'll have to escape are the delimiters inside the text, $, @, and %.