Re: even rows for checkbox forms with no splitting of boxes from values
- From: "Christopher F. Falzone" <ctiggerf@xxxxxxxxx>
- Date: Sun, 7 May 2006 07:08:15 CST
mike wrote:
Christopher:
Thank you for the solution to my problem. I had been thinking about using
'mod' on the array length with a denominator equal to the width of the row,
but I hadn't a good idea of how to implement it. The 'ceil' function did it
smoothly.
Yep, I used the ceil function so that you didn't end up with more
elements in the last column then the other. I the case that you had 26
elements and 5 columns just taking 26/5 would round to 5 per leaving 6
in the last.
Takeaway lesson #1 is I have to learn how to do HTML better now
that I'm mildly competent in Perl.
Well, if that's what your using perl for. <shrug>
I've got a book on HTML by E. Castro
I'm trying to use to get going.
I like the O'Reilly books myself. Just a personal preference.
My big Perl project is to implement 'state
saving' in my 30-page script, and my studying of the book 'CGI Programming
with Perl' from O'Reilly suggests the easiest way to do this is with hidden
fields, so that's where I'm going.
State saving really depends on what the script is already doing. If
you have a really long form you can split it up into several small ones
and save the state via hidden fields. This does, however, leave your
script up to some vulnerabilities. Once someone fills out the form
once, they can look at the last page's source and see every variable
you use. This would allow them to create an auto-form submitter fairly
easy.
Some other options to think about may be: saving your info to a flat
file, or database table. Or, if you want to stick with something more
html-ish .. you could also use cookies to save state.
If any expert objects disagrees with
this, please feel free to let me know.
Not an expert really, and I don't object. If you could give some more
specifics of the actuall script and what it is doing and what you want
it to do an what you have tried .. we can prolly help you out a little
more.
I also know now what ROTFLOL WTIME means. Valuable in itself.
Yeah .. I'm a gamer at heart, so I tend to use the more common
abreviations some times. LOL
Thanks to Christopher and to Tom.
NP
YW
Mike
"Christopher F. Falzone" <ctiggerf@xxxxxxxxx> wrote in message
news:1146666998.218600.75420@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Well I think I have a solution for ya.
I really don't like the control and look of how the CGI.pm
checkbox_group has. So I usually roll my own checkboxes. I am sure if
read the CGI.pm stuff there is a way to completely control the way it
looks. The other problem was how it looks different in different
browsers which .. is unfortuanatly always going to be an issue.
In the solution below I wanted to randomize the test script a little
more than what you had, based on what you originally posted as your
question. My solution invloves setting the number of columns you want
your checkboxes to show up in and then makeing a table with many
columns and figuring out how many boxes to put in each column.
This can be good and bad .. for one it lines things up, organizes them
and stops the label from wrapping to the next line. on the other hand
instead of your checkboxes going in this order ...
1 2 3 4
5 6 7 ...
They will now go in this order
1 5
2 6
3 7
4 ...
But if you play with the script a little I'm sure you can some up with
a way to rearrange them in the original order.
so here goes ...
#!/usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard -no_xhtml);
use diagnostics;
#added warnings
use warnings;
#needed later
use POSIX qw(ceil);
print header, start_html(-title=>'uneven');
#I wanted to randomize your strings a little more
#this is to create an array with 25-50 strings 2-10 in length
#just an array with some characters
my @chars = ('a'..'z','A'..'Z','0'..'9');
my @matches = ();
# random number of strings from 25-50
my $num_strings = int(rand 26)+25;
foreach(1 .. $num_strings) {
my $new_str = '';
my $str_len = int(rand 9)+2; # random string lend from 2-10
#now create the string
foreach(1 .. $str_len) { $new_str .= $chars[rand @chars]; }
#add it to the array
push @matches, $new_str;
}
#next let's set up a form with all members from the array
print start_form(-method=>"POST",-action=>"findme.html");
@matches=sort(@matches);
#eliminate duplicates in array @matches:
my %temp=();
@matches=grep ++$temp{$_}<2, @matches;
my $lenmatches=@matches;
####################################################
#this is the guts of the solution I could come up with
#I'm not overly fond of the checkbox group method in the CGI
#so here is how I would do it
#change the following to the number of columns you want
my $num_columns=5;
my $num_in_column=ceil($lenmatches/$num_columns);
#now I'm going to put the check boxes in a table
print "<table cellpadding='3' cellspangin='0'>
<tr nowrap><td valign='top'>\n";
my $printed=0;
for(my $i=0; $i<$lenmatches; $i++) {
if($printed==$num_in_column) {
print "</td><td valign='top'>";
$printed=0;
}
"<label><input type='checkbox' name='onlyd' value='$matches[$i]' />
$matches[$i] </label><br>\n";
$printed++;
}
print "</td></tr></table>\n";
#end guts
################################################
#ok now for show let's do it all like 4 more times
#and randomize the number of columns for some play
foreach (1 .. 4) {
@chars = ('a'..'z','A'..'Z','0'..'9');
@matches = ();
$num_strings = int(rand 26)+25;
foreach(1 .. $num_strings) {
my $new_str = '';
my $str_len = int(rand 9)+2;
foreach(1 .. $str_len) {
$new_str .= $chars[rand @chars];
}
push @matches, $new_str;
}
print start_form(-method=>"POST",-action=>"findme.html");
@matches=sort(@matches);
%temp=();
@matches=grep ++$temp{$_}<2, @matches;
$lenmatches=@matches;
#just going to randmoize the number of columns 1-10
$num_columns=int(rand 10)+1;
$num_in_column=ceil($lenmatches/$num_columns);
print "<hr><table cellpadding='3' cellspangin='0'>
<tr nowrap><td valign='top'>\n";
$printed=0;
for(my $i=0; $i<$lenmatches; $i++) {
if($printed==$num_in_column) {
print "</td><td valign='top'>";
$printed=0;
}
"<label><input type='checkbox' name='onlyd' value='$matches[$i]' />
$matches[$i] </label><br>\n";
$printed++;
}
print "</td></tr></table>\n";
}
print p(submit,endform,end_html);
mike wrote:
Tom:
It depends upon the browser! I'm new to this, so I was unaware that this
was an issue, but running my script with Firefox v1.5.0.2 gives broken
strings which wrap, but IE gives nice, clean, even lines. Using
'-columns=>5' didn't work for either browser, ufortunately. I'd rather
not
have to ask the users to employ a particular browser. Does anyone know
how
to tell Firefox to act like Internet Explorer? Or make Firefox behave?
Thank you for the help.
"Tom" <tom@xxxxxxxxxxxxx> wrote in message
news:%FM5g.983$VV2.74286@xxxxxxxxxxxxxxxxxxxxxxxx
Mike,
I ran your revised script. Even when resizing my screen many times,
the
checkboxes and text remained on the same line.
You may want to force the number of checkbox rows or columns in your
checkbox_group function to improve your format.
Try ..
$co->p,$co->checkbox_group(-name=>'onlyd', -Values=>\@matches, -columns=>5
);
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
.
- References:
- Re: even rows for checkbox forms with no splitting of boxes from values
- From: Tom
- Re: even rows for checkbox forms with no splitting of boxes from values
- From: mike
- Re: even rows for checkbox forms with no splitting of boxes from values
- From: Christopher F. Falzone
- Re: even rows for checkbox forms with no splitting of boxes from values
- From: mike
- Re: even rows for checkbox forms with no splitting of boxes from values
- Prev by Date: Applications and Batch Files
- Next by Date: Re: The equals greater than operands
- Previous by thread: Re: even rows for checkbox forms with no splitting of boxes from values
- Next by thread: CGI.pm Timeout on POST data
- Index(es):
Relevant Pages
|