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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI creating HTML with form: Default "Values"? 1

Status
Not open for further replies.

operaguy

Programmer
Aug 19, 2002
28
US
A normal HTML page with form post to a the CGI script below, which in turn generates a page. How do I default data into the value= of the form-to-be generated?

Here is the cgi (it is being posted-to by a normal html form-post sending 'amount', 'first' and 'last'

NOTE: the calling of the "HOP" file and the "insert_signature" thing are not at issue...they work....it's the defaulting of values into the input fields on the page being built that is my problem.

---------------------------------------------

#!/usr/bin/perl -I.

use CGI qw/:standard/;
use HOP qw(insert_signature);

my $query = new CGI;

print $query->header(-type=>"text/html");

print<<EOF;
<html><body>
<h1>Sample Post</h1>
<p>This page creates a button (seen below) that will send the customer to the HOP to complete their order.<br />
The customer will be charged the amount they entered on the previous page, in this case:
EOF
;

print "<strong>\$" . $query->param('amount') ."</strong></p>\n";
print "<strong>\First name passed: " . $query->param('first') ."</strong></p>\n";
print "<strong>\Last name passed: " . $query->param('last') ."</strong></p>\n";
print<<EOF;
<form action=" method="post">
EOF
;

insert_signature($query->param('amount'));



print<<EOF;
<BR>First name (hopefully defaulted from prior html page): <input type="text" name="First" value="$query->param('first')">
<BR>Last name (hopefully defaulted from prior html page): <input type="text" name="Last" value="$query->param('last')">
<BR><BR><BR><input type="submit" name="submit" value="Donate Now!">
</form>
</body></html>
EOF
;

--------------------------------------

value="$query->param('first')" does not work.

My appologies for such a simple issue, but I am not an expert PERL programmer, and the CC gateway company's tech support for PERL is very deficient.

Link to this sequence in action:


John
 
you seem to be getting the hash reference.

try dereferencing the hash with $$query->param('first')

i.e. put two dollar signs

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
this
Code:
value="$query->param('first')"
will never work with cgi.
use a variable to place the content of it first. Like this
Code:
$first=$query->param('first');
$last=$query->param('last');
print<<EOF;
<BR>First name (hopefully defaulted from prior html page): <input type="text" name="First" value="$first">
<BR>Last name (hopefully defaulted from prior html page): <input type="text" name="Last" value="$last">
......
......

Bytheway 1DMF the cgi params are Not scalar references so you cannot dereference them as you suggested.


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
You can use the Params Hash to do this

Code:
use CGI qw/:standard -no_debug/;
[b]my %FORM = CGI::Vars();[/b]

print<<EOF;
<BR>First name: <input type="text" name="First" value="[b]$FORM{'first'}[/b]">
<BR>Last name: <input type="text" name="Last" value="[b]$FORM{'last'}[/b]">
<BR><BR><BR><input type="submit" name="submit" value="Donate Now!">
  </form>
</body></html>
EOF

HTH,
San

---
cheers!
san
smoking3vc.gif


print length "The answer to life, universe & everything!
 
wow, great responses, thanks all. I just got home and will explore these solutions late tonight and report back.
John
 
there is an edit feature, use the "Preview Post" button instead of the "Submit" button and you have a chance to edit. But after you post there is no edit.
 
so you can only dereference scalars?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
also
my %FORM = CGI::Vars();
does CGI::Vars only hold post vars?

what about get/URL vars , are they available in a separate function.

i.e.

my %URL = CGI::URL_Vars(); or CGI::Get_Vars();

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
so you can only dereference scalars?

Of course not, you already know that. The problem is that this is not a reference to a scalar: $query->param('first')
it's a reference to class method (a function) of the $query object.
 
sorry Kevin, termernology threw me for second, of course i knew the answer.

It's the OO part that threw me if it was a proper hash it would be $query->param{'first'} - ie. curly braces not parentheses ()

I really need to learn more on OO and classes, so much work on my plate at the moment, so tired, I need a holiday!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top