[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] CGI.pm start_form() bug? I guess not...



Given this program:

---
#!/usr/bin/perl

use CGI qw( escapeHTML );

my $q = new CGI;
print $q->header;

print
   "x is " . $q->param("x") . "<br>\n",
   escapeHTML($q->start_form), "<p>\n";

$q->param("x", "one");
print
   "x is " . $q->param("x") . "<br>\n",
   escapeHTML($q->start_form), "<p>\n";

$q->param("x", "two");
print
   "x is " . $q->param("x") . "<br>\n",
   escapeHTML($q->start_form), "<p>\n";
---

Hitting it with this URL

   http://razorbill/~jhannah/index.pl?x=blah   

I was surprised by this output:

---
x is blah
<form method="post" action="/~jhannah/index.pl?x=blah" enctype="multipart/form-data"> 

x is one
<form method="post" action="/~jhannah/index.pl?x=blah" enctype="multipart/form-data"> 

x is two
<form method="post" action="/~jhannah/index.pl?x=blah" enctype="multipart/form-data"> 
---

I thought that the 'action' URL should keep changing to reflect the new state of the variable x... 

So, down in HTML land...

What happens if you POST to a form w/ parameters in the URL? Are the URL parms honored? What if the variable x is in both the URL AND the POST with different values? Which one does it honor?

Testing in raw HTML... Given this form:

<form method="post" action="/~jhannah/parms.pl?x=blah" enctype="multipart/form-data">
<input type=submit>
</form>

I was surprised that parms.pl[1] does NOT receive/see param x set to blah.

As expected, though: given this form:

<form method="post" action="/~jhannah/parms.pl?x=blah" enctype="multipart/form-data">
<input type=textfield name=x>
<input type=submit>
</form>

parms.pl will receive whatever you type into the textfield named x.


What I learned today: You can have all the parameters you want in the querystring of the 'action' of a form (method="POST"), but they will all be ignored. Pay them no heed...

Go figure! -grin-

j



[1] parms.pl source code (Dump all params to the screen (err... browser).)

#!/usr/bin/perl

use CGI;

my $q = new CGI;
print $q->header,
   "<h1>Params you submitted:</h1>";
foreach ($q->param) {
   print "<b>$_:</b> " . $q->param($_) . "<br>\n";
}