RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
='TITLE', defa=$title, size=50,}); foreach (sort keys %ids) { print Tr( td({-align='RIGHT'},$ids{$_}{label},b(':')), td({-align='LEFT'}, textfield( -name=$ids{$_}{name}, -default=$ids{$_}{defa}, -size =$ids{$_}{size}, -maxlength =$ids{$_}{size})),\n); } print /TABLE\n; print center($q-submit({-name='Get', -value=' Get '})); print p( center( 'View Estimate by:', $q-radio_group(-name='ACTION', -values=['ACCOUNT', 'CUSTOMER']), hr({width='80%'}), ) ); print $q-endform, \n; # offending code maybe ? == == # # form for input of estimates, sends confirmation/results of submit # to toolbar ... # print $q-startform({-target=toolbar}), # # build table by Category There is more but the extra is being added on the above form ... But does not appear to be present on other endform calls ... John W Moon State of Florida State Technology Office 1255 S Main St. Georgetown, TX 78626 Email: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Phone: (512) 868-8874 -Original Message- From: Curtis Poe [mailto:[EMAIL PROTECTED]] Sent: June 21, 2001 11:28 To: CGI Beginners Subject:RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ? --- Moon, John [EMAIL PROTECTED] wrote: Yes, I assumed it is trying to help me ... But don't want it's (CGI's) help ... in this case Any one know how to stop it ... I do a $q-new CGI after getting my values from the post ; and yes I use $q-endform; John W Moon Um, what exactly do you mean when you say that you do $q-new CGI after getting your values form the post? Is that the syntax that you are using and, if so, what are you trying to accomplish? Again, showing us your code would be a big help. Cheers, Curtis = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
print $q-endform, \n; # offending code maybe ? == == # # form for input of estimates, sends confirmation/results of submit # to toolbar ... # I'm not sure if this is what you want, but couldn't you just replace the above line of code with print /FORM; That will at least get rid of your hidden tag and close the form.
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Hi John, There are a variety of issues with this, so I'll take it from the top, but starting with the issue with you are concerned. I hope you don't take any of this personally, as it's just intended to be helpful: print $q-endform; This does indeed print the hidden field that you are concerned with. Here's a solution: print /form; Frankly, I have no idea why that works, or why the hidden field is printed in the first place. I've read through much of the CGI.pm code, but this is one that I have never encountered. use CGI qw(:standard :all *table); You're importing a bunch of functions into your namespace, but you use the object oriented interface ($q-...). You can drop the import as it's irrelevant and will slow things down. Just have use CGI;. However, on closer inspection, I realize that you appear to have mixed both the function and object oriented interfaces. This will merely cause confusion for maintenance programmers down the road. You should stick with one interface or the other. From what I see with your code, it would be easier to switch the function calls to object calls: center() becomes $q-center() b() becomes $q-b() h3() becomes $q-h3() And so on... This is an issue because CGI.pm has to do a lot of work to import those functions into the calling namespace. Since this module already has a lot of overhead, this is simply extra, needless work if you are using the object oriented interface. foreach ($q-param) { $REQUEST{$_}=$q-param($_); } I assume that you know your form better than I do, but are you aware that the above snippet will only return the first value for a param if that param has several values? For many forms, this will not make a difference. sub BuildForm { use strict; Two things here: 1. It really helps if you indent the code in a sub. Indentation gives on an excellent view of how things are arranged and scoped. Just glancing at your code, I can't tell where the sub ends (or if it even ends in the snipped you sent. Indenting is a Good Thing. 2. use strict is not needed here. This pragma is lexically scoped. Thus, it will be in effect in the entire scope of where it's declared. This means that having a 'use strict' at the top of a program will affect the entire file (even across package boundaries) in which it's present. center(h3('TechDirect Estimates')); $q-center($q-h3('TechDirect Estimates')); print center(font({-size=3},'Fiscal Year'), print $q-center($q-font({-size=3},'Fiscal Year'), #print start_table; print table\n; [snip] foreach (sort keys %ids) { print Tr( td({-align='RIGHT'},$ids{$_}{label},b(':')), td({-align='LEFT'}, textfield( -name=$ids{$_}{name}, -default=$ids{$_}{defa}, -size =$ids{$_}{size}, -maxlength =$ids{$_}{size})),\n); } print /TABLE\n; The above code for printing a table is something that I see a lot in code. This happens because of the way that that tables need to be built. Here's a somewhat cleaner, object oriented method of building it, assuming that you've already created the %ids hash: my $table = ''; foreach (sort keys %ids) { $table .= $q-Tr( $q-td({-align='RIGHT'},$ids{$_}{label},$q-b(':')), $q-td({-align='LEFT'}, $q-textfield( -name = $ids{$_}{name}, -default = $ids{$_}{defa}, -size = $ids{$_}{size}, -maxlength = $ids{$_}{size})),\n); } print $q-table( $table ); There are more function orient calls, but I think this should give you a good feel for it. Cheers, Curtis Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
On 21 Jun 2001, at 9:50, Curtis Poe wrote: foreach ($q-param) { $REQUEST{$_}=$q-param($_); } I assume that you know your form better than I do, but are you aware that the above snippet will only return the first value for a param if that param has several values? For many forms, this will not make a difference. I am working on a script which has just this problem. My solution was to look for the name of the field, get an array and assign the array as the value in the hash. Besides knowing which fields may contain multiple values, is there a way to determine the number of values returned by $q-param(foo)? Thanks, William
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
--- Moon, John [EMAIL PROTECTED] wrote: Yes, ... it's gone ... Thanks ... Interestingly, doesn't appear on subsequent calls to endform ... so I'm a little concerned I don't understand what CGI (or I) am doing ... it would seem like it should always give the same results ... A quick glance at the CGI docs (which I should have done in the first place!) shows that -nosticky will stop CGI.pm from outputting the hidden .cgifields tags: use CGI qw/-nosticky/; CGI.pm uses sticky fields. If you submit a form and CGI.pm redisplays that form using its HTML shortcuts, it automatically fills in all of the form values for you if your param names match the HTML shortcut attribute names. Apparently, CGI.pm uses the hidden .cgifields tag to let it know that it's processing a 'sticky' form. Cheers, Curtis Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
--- William McKee [EMAIL PROTECTED] wrote: On 21 Jun 2001, at 9:50, Curtis Poe wrote: foreach ($q-param) { $REQUEST{$_}=$q-param($_); } I assume that you know your form better than I do, but are you aware that the above snippet will only return the first value for a param if that param has several values? For many forms, this will not make a difference. I am working on a script which has just this problem. My solution was to look for the name of the field, get an array and assign the array as the value in the hash. Besides knowing which fields may contain multiple values, is there a way to determine the number of values returned by $q-param(foo)? Thanks, William Um, yes, but it looks ugly. Generally I only use the following method if I have to generate a form on the fly. Here's one way of handling something like this: my $foo_count = scalar @{[param('foo')]}; This will tell you how many values have been returned for foo. Another way: my @foo = param('foo'); my$foo_count = scalar @foo; What's going on is that param() uses 'wantarray' to determine if it's assigning to a scalar or array. If it's assigning to a scalar, it only returns the first value (or only value, if that's all there is). Otherwise, it's going to return a list. What the first method does it the following: [ param('foo') ] The square brackets force param() to be evaluated in a list context. @{[param('foo')]} The @{...} forces the listref to be dereferenced into an anonymous array. scalar @{[param('foo')]}; That scalar function then forces the anonymous array to be evaluated in scalar context, thus returning the number of elements. If only one form element is returned for 'foo', param will just return a one element list and the above construct returns the value '1'. Cheers, Curtis Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Curtis == Curtis Poe [EMAIL PROTECTED] writes: Curtis my $foo_count = scalar @{[param('foo')]}; That's nice, but I prefer: my $foo_count = () = param('foo'); Less typing, less work for the machine. Less noise. More magic, though. Oops, arguable on that. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Curtis == Curtis Poe [EMAIL PROTECTED] writes: Curtis my $foo_count = scalar @{[param('foo')]}; That's nice, but I prefer: my $foo_count = () = param('foo'); Less typing, less work for the machine. Less noise. More magic, though. Oops, arguable on that. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - Let me guess ... param('foo') is assigned to a list ... the list is assigned to $foo_count in a scalar context so the number of elements are returned. Right? Glenn Tillema [EMAIL PROTECTED] ADC Telecommunications, Inc. PO Box 1101, MS 508 Minneapolis, MN 55440-1101 Learn about ADC - The Broadband Company - www.adc.com
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
my $foo_count = () = param('foo'); Tillema, Let me guess ... param('foo') is assigned to a list Tillema,... the list is assigned Tillema, to $foo_count in a scalar context so the number of Tillema, elements are returned. Tillema, Right? Probably simpler than that. param is invoked in a list context, so it does its listy-thing, and returns a list of N elements. This list attempts to be assigned to the () list, which tosses everything after the 0th element (that is, EVERYTHING) as unneeded. However, since that list assignment op was in a scalar context, it returns the number of original elements (not the number of kept elements), and that's back to N again. And that N goes into $foo_count. There's never a list assigned to $foo_count in a scalar context... the phrase doesn't even make sense to me. :) You can't assign a list to $foo_count. It can never happen. Never. A list cannot exist in a scalar context... the guts of Perl mandates that. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - That's how it was phrased in the camel; List assignment in scalar context returns the number of elements produced by the expression on the _right_ side of the assignment... Your explanation certainly goes into much more detail, however. Thanks! Glenn Tillema [EMAIL PROTECTED] ADC Telecommunications, Inc. PO Box 1101, MS 508 Minneapolis, MN 55440-1101 Learn about ADC - The Broadband Company - www.adc.com
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Curtis, Thank you for the suggestion ... This is for beginners and I have a lot to learn ! ... I'll use the OO format - just got lazy ... never used strict before because it was s strict but some guy named Curtis (and others) kept saying to use it so Thanks for letting me know about the scoping... Yes, I knew about what param returned but haven't needed to have a multi-value token (array) returned ... so far ... and appreciate the further discussion ... Thanks for the tip on $table .= ... again I needed to get out of my box ... and that why I like this forum ... I work alone (remote) and this has been a BIG help to me ... Hope I can help others down the road ... In my doc (from perldoc) I don't see the pragma listed... which brings me to the question how do I know which version of CGI I have ... I don't install software at this shop ... and don't have root privileges ... in fact much to my dismay they have multiple versions of Perl installed ... so when I run perldoc which doc's am I getting ? Althought it says loosely found as .../5.00502 ... after a lot of other stuff ... What is the current stable version of CGI ... ? $ENV{MANPATH} = /usr/share/man:/usr/local/man -V reports: SUN2perl5.00502 -V|more # which is my shebang Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration: ... where reports: SUN2perl -V|more Summary of my perl5 (5.0 patchlevel 3 subversion 0) configuration: ...
Re: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Tillema, == Tillema, Glenn [EMAIL PROTECTED] writes: There's never a list assigned to $foo_count in a scalar context... the phrase doesn't even make sense to me. :) You can't assign a list to $foo_count. It can never happen. Never. A list cannot exist in a scalar context... the guts of Perl mandates that. Tillema, That's how it was phrased in the camel; List assignment in scalar context Tillema, returns the number of elements produced by the expression on the _right_ side Tillema, of the assignment... Your explanation certainly goes into much more detail, Tillema, however. Thanks! Ahh, there's HUGE difference between list assignment _in_ scalar context and list assigned _to_ [a scalar] Let's draw that out. First is: $foo_length = () = SOME_LIST == list assignment in = __ scalar context Second might mean something like: $foo_length = SOME_LIST # although this can't happen = list = assigned to === scalar See the difference? And the latter can't happen. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
RE: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Tillema, That's how it was phrased in the camel; List Tillema, assignment in scalar context Tillema, returns the number of elements produced by the Tillema, expression on the _right_ side Tillema, of the assignment... Your explanation certainly Tillema, goes into much more detail, Tillema, however. Thanks! Ahh, there's HUGE difference between list assignment _in_ scalar context and list assigned _to_ [a scalar] Let's draw that out. First is: $foo_length = () = SOME_LIST == list assignment in = __ scalar context Second might mean something like: $foo_length = SOME_LIST # although this can't happen = list = assigned to === scalar See the difference? And the latter can't happen. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - I know I've certainly tried it ... :) I see the difference, thanks! Glenn Tillema [EMAIL PROTECTED] ADC Telecommunications, Inc. PO Box 1101, MS 508 Minneapolis, MN 55440-1101 Learn about ADC - The Broadband Company - www.adc.com
Re: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
At 04:21 PM 06/21/2001 -0400, Timothy Kimball wrote: Randal L. Schwartz wrote: : ... : Second might mean something like: : : $foo_length = SOME_LIST # although this can't happen : = list : = assigned to : === scalar : : See the difference? And the latter can't happen. Sure it can. Well, the list itself doesn't get assigned to the scalar, but an assignment does get made: The last element of SOME_LIST to $foo_length. So my $number_of_pets = ('dog','cat','iguana'); sets $number_of_pets to 'iguana'. Methinks you actually /validated/ Randal's post, not contradicted it ;) Randal said: Ahh, there's HUGE difference between list assignment _in_ scalar context and list assigned _to_ [a scalar] So your example would fit in the list assignment _in_ scalar context category...the keyword being assignMENT, and not assignED aloha, mel mel matsuoka Hawaiian Image Productions Chief Executive Alphageek(vox)1.808.531.5474 [EMAIL PROTECTED](fax)1.808.526.4040
Re: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
--- Timothy Kimball [EMAIL PROTECTED] wrote: Randal L. Schwartz wrote: : ... : Second might mean something like: : : $foo_length = SOME_LIST # although this can't happen : = list : = assigned to : === scalar : : See the difference? And the latter can't happen. Sure it can. Well, the list itself doesn't get assigned to the scalar, but an assignment does get made: The last element of SOME_LIST to $foo_length. So my $number_of_pets = ('dog','cat','iguana'); sets $number_of_pets to 'iguana'. -- tdk Actually, you're dealing with a well-documented, but poorly understood feature. Try this: my $number_of_pets = ('dog','cat','iguana'); print $number_of_pets; my @pets = ('dog','cat','iguana'); $number_of_pets = @pets; print $number_of_pets; $number_of_pets = ('dog','cat',@pets); print $number_of_pets; @number_of_pets = ('dog','cat',@pets); print scalar @number_of_pets; The first print results in 'iguana' and the second and third print statements print 3. The fourth print display a 5. What's going on here is subtle. Putting parens around those scalars creates a list literal. When a list literal is accessed in scalar context, it evaluates each item in scalar context and returns the value of the final element. Since, in the third example, the array is the third element, it's evaluated in scalar context, as expected. So why do the third and fourth examples have different outputs? Because lists are not arrays and do not behave as such. Cheers, Curtis Poe = Senior Programmer Onsite! Technology (http://www.onsitetech.com/) Ovid on http://www.perlmonks.org/ __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Re: Extra INPUT TYPE=hidden NAME=.cgifields VALUE=ACTION ?
Mel Matsuoka wrote: : Randal L. Schwartz wrote: : : ... : : Second might mean something like: : : : : $foo_length = SOME_LIST # although this can't happen : : = list : : = assigned to : : === scalar : : : : See the difference? And the latter can't happen. : : Sure it can. Well, the list itself doesn't get assigned to the scalar, : but an assignment does get made: The last element of SOME_LIST to : $foo_length. So : : my $number_of_pets = ('dog','cat','iguana'); : : sets $number_of_pets to 'iguana'. : : : Methinks you actually /validated/ Randal's post, not contradicted it ;) Actually, I was reacting in a blind fury to the words can't happen. I hate to see that in a post about Perl. ;) -- tdk