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

Little form parsing question... 1

Status
Not open for further replies.

perlone

Programmer
Joined
May 20, 2001
Messages
438
Location
US
Hi,

I have a script that uses lots of subroutines and most of them it uses Form Parsing. Like this:

if (query =~m/deposit/) {
&deposit;
}


sub deposit {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
$FORM{$name} = $value;
}

&header(&quot;Deposited: $FORM{'deposit'}&quot;,&quot;Deposit&quot;);
exit;
}



Don't know why but perl doesn't parse. Is there any script or module that forces form to parse at any given time?


-Aaron
 
Where is it getting the value of query ($query?) to check which subroutine to run? You probably need to parse the form values FIRST (and then you'll only have that code once), then check which subroutine to run. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
not working. I have the following:



if ($query =~m/money_management/) {
$deposit = $FORM{'deposit'};
&header(qq~
Welcome to Money
Mangement, $username. From here you could manage your safely. You
could deposit as well as withdrawl. You have <strong>$gold </strong>Gold
to deposit and you have <strong>$withdraw</strong> in your
account.</font></p>
<div align=&quot;left&quot;>

<table border=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td valign=&quot;top&quot;><font color=&quot;#FFFFFF&quot; size=&quot;2&quot;
face=&quot;Arial&quot;>Deposit:</font></td>
<td><input type=&quot;text&quot; size=&quot;20&quot; name=&quot;deposit&quot;
value=&quot;$gold&quot;> <form
action=&quot;main.cgi?email=$email&pass=$pass&deposit&quot;

method=&quot;POST&quot;>
<p><input type=&quot;submit&quot; value=&quot;Deposit&quot;></p>
<p> </p>
</form>
</td>
</tr>
<tr>
<td><font color=&quot;#FFFFFF&quot; size=&quot;2&quot; face=&quot;Arial&quot;>WithDrawl:</font></td>
<td><input type=&quot;text&quot; size=&quot;20&quot; name=&quot;withdraw&quot;
value=&quot;$withdraw&quot;> </td>
</tr>
<tr>
<td> </td>
<td><form
action=&quot;main.cgi?email=$email&pass=$pass&withdrawl&quot;
method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;email&quot; value=&quot;$email&quot;><input
type=&quot;hidden&quot; name=&quot;pass&quot; value=&quot;$pass&quot;><input
type=&quot;hidden&quot; name=&quot;step&quot; value=&quot;withdrawl&quot;><p><br>
<input type=&quot;submit&quot; value=&quot;WithDraw&quot;></p>
</form>
</td>
</tr>
</table>
</div>

<form method=&quot;POST&quot;>
<p align=&quot;center&quot;><font color=&quot;#FFFFFF&quot; size=&quot;2&quot; face=&quot;Arial&quot;>|</font><a
href=&quot;main.cgi?email=$email&pass=$pass&quot;><font
color=&quot;#408080&quot; size=&quot;2&quot; face=&quot;Arial&quot;><u>Back</u></font></a><font
color=&quot;#FFFFFF&quot; size=&quot;2&quot; face=&quot;Arial&quot;>|</font></p>
</form>

<form method=&quot;POST&quot;>
<p> </p>
</form>
~,&quot;Money Management&quot;);
exit;
}

if ($query =~m/deposit/) {
&readform;
print &quot;Deposited $FORM{'deposit'}&quot;;
}


I'm not that good at this subroutine stuff, but would this be easily filxed with the 'return' function? Sorry to bother you again.
 
I think part of your problem is that you are mixing GET and POST methods. When you have a form action with parameters on it, that should indicate a GET method. What you should do is remove the parameters from the action url and use hidden fields to pass those values to your program. Then they'll be passed along with any input fields on the form. I also notice that the parameter &quot;deposit&quot; that you have in red above doesn't have a name attached to it.

You might also have an easier time using the CGI module to parse the values returned from the form. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Thanks, i'll try that:-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top