Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a web form with Perl

Status
Not open for further replies.

GrichG

Programmer
Feb 9, 2006
4
0
0
US
Hi, I'm a new guy and I hope this question has not been answered over and over..........

I have a web page with a form that has several hidden fields. When the submit button is pressed it calls a cgi script. That script sends out a couple of emails and creates a second web page with a form with some of the hidden fields from the first page. When the submit button on the second form is pressed it calls a cgi script from a commercial card processing company.

The problem comes when I build the second form. The information in some of the fields has two or more words, such as "PersonsName". If the name is Rich Giles, only the Rich gets passed to the second forms field. There are several fields that have more than one word in them.

An example of the script is:

my $personname;

$personname="Rich Giles"; (it fails even if I hard code the value into the variable)

print "All the page required lines"
print '<body>';
print '<form name="entry" method="POST" action="print "<input type='hidden' name='card-name' value= $personname>";
print "<input type='submit' name='Button' value='CLICK HERE TO PROCESS THE PAYMENT' />";


The resulting field on the form only shows "Rich".
If I hard code "Rich Giles" into the "card-name" input line, both names are passed.
If I cause $personname to print on the second web page it prints both names "Rich Giles"
If I remove the type='hidden' from the "card-name" input line so I can see the value setting there before I click submit, what shows is one name, "Rich" only.

Is there something I need to know about scaler variables and building a web form in Perl?

Thanks
Rich
 
This was answered on another forum.......
**************************************************
You need to quote the value or the interpreter will terminate after encountering a space.
This behavior will happen in most languages.
When the variable isn't quoted it will be interpreted as an integer.
As soon as it encounters a space it figures that is the end of the integer.
When you quote it, it will interpret it as a string.

I have noted that this behavior happens primarily when a variable is being inserted into an input element.

print "<input type='hidden' name='card-name' value='$personname'>";

These two methods will print the same results:

print "<input type='hidden' name='card-name' value=Rich Giles>";
print "<input type='hidden' name='card-name' value=$personname>";

And these methods are correct:

print "<input type='hidden' name='card-name' value='Rich Giles'>";
print "<input type='hidden' name='card-name' value='$personname'>";
__________________
Jerry Broughton
 
Yes, as you stated, this was not a perl issue, but an HTML issue.

However, it might help you to start using the alternative quoting operators like qq, especially when working with html.

Code:
my $personname = "Rich Giles";

print qq{All the page required lines};
print qq{<body>};
print qq{<form name="entry" method="POST" action="[URL unfurl="true"]https://creditcardco.com/pay.cgi">;[/URL]
print qq{<input type="hidden" name="card-name" value="$personname">};
print qq{<input type="submit" name="Button" value="CLICK HERE TO PROCESS THE PAYMENT" />};
 
Another technique to bear in mind, Rich, is the "View Source" function on your web browser.

Use it to view the HTML actually generated by your CGI scripts, as opposed to what you think they're generating. If you'd done that, you might have picked up on the missing quotes.



-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
I would suggest learning the CGI module.
<code>
print start_form, hidden('card-name', "$personname"), submit('Button', 'CLICK HERE TO PROCESS THE PAYMENT'), end_form;
</code>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top