Gangabass has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I need to get params from HTML page which uses XHTML 1.1 Strict DTD. So there is no name attributes in input element but only id attributes.

<input type="text" id="password" />

But then i try to get params for that attributes i got nothing :-(

#!/usr/bin/perl use strict; use warnings; use CGI; my $query = new CGI; my @names = $query->param();

So i get only empty @names array. And

my $pass = $query->param("password");

did't work too.

But than i add to one input element name param i can see it in my cgi-script.

<input type="text" id="password" name="password" />

Is there a way to work with id params in CGI.pm?

Replies are listed 'Best First'.
Re: [CGI.pm] Working with forms which uses strict DTD
by moritz (Cardinal) on May 15, 2008 at 11:40 UTC
    I'm pretty sure that the browser is to blame, not CGI.

    Take a look at the raw POST request, for example with a sniffer like wireshark. If the browser doesn't send the params, there's now way CGI.pm can deliver you the values.

    Update I tested it with a HTML form which contains only ids and no names, and this is what went over the wire:

    OST / HTTP/1.1 Host: moritz User-Agent: Mozilla/5.0 (X11; U; Linux i686; de-DE; rv:1.8.1.14) Gecko +/20080404 Iceweasel/2.0.0.14 (Debian-2.0.0.14-0etch1) Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9 +,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: de-de,de;q=0.8,en-us;q=0.7,en;q=0.5,en-gb;q=0.3,nb;q= +0.2 Accept-Encoding: gzip,deflate Accept-Charset: UTF-8,* Keep-Alive: 300 Connection: keep-alive Referer: http://moritz/de/bar Content-Type: application/x-www-form-urlencoded Content-Length: 0

    You can see from teh Content-Length that no form data is actually submitted - bad luck for you. (Note that my test HTML form didn't have a xhtml strict DTD, so it might work for some browsers with that DTD. But I don't think it works with the broken browsers that >50% of all people use.)

      Hmmm, you are right!

      I test it in Opera 9.20 and Firefox 2.0.0.9 and i see that browser did't send data. So it's not a Perl problem.

      Thanks!

Re: [CGI.pm] Working with forms which uses strict DTD
by Fletch (Bishop) on May 15, 2008 at 12:36 UTC

    Erm, I don't know where you (or more to the point, whomever's generating the HTML with the form) got the idea that XHTML 1.1 input elements can't have a name attribute since the table for form elements (reached from the XHTML 1.1 spec) shows that name looks to be a perfectly valid attribute.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.